2 つ以上のスタンドアロン OpenTK GLControls を実装しようとしています。フォームの読み込み時に、読み込み時に両方をレンダリングして表示する必要があります。下の図では、私の問題が表示されます。1 つは正しくレンダリングされますが、もう 1 つはレンダリングされないままです。
mouse_drag 前の GL スクリーンショット
エラーが発生したコントロールで mouse_drag アクションを実行すると、正しくレンダリングされます。
mouse_drag 後の GL スクリーンショット
これが私のメインフォームのコードです。GLControl オブジェクトを作成して追加します。
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Threading.Tasks
Imports OpenTK
Imports OpenTK.Graphics
Imports OpenTK.Graphics.OpenGL
Public Class MultipleDisplay
Private Sub MultipleDisplay_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Creating and adding the controls.
'The load event prompts the user to choose a file to build the objects.
Dim task2 As GLControlTask = New GLControlTask()
task2.MakeCurrent()
task2.Width = 400
task2.Height = 400
task2.Top = 0
task2.Left = 450
Me.Controls.Add(task2)
'The load event prompts the user to choose a file to build the objects.
Dim task1 As GLControlTask = New GLControlTask()
task1.MakeCurrent()
task1.Width = 400
task1.Height = 400
task1.Top = 0
task1.Left = 0
Me.Controls.Add(task1)
'INITIAL PAINT
task2.MakeCurrent()
task2.Invalidate()
task1.MakeCurrent()
task1.Invalidate()
End Sub
End Class
GLControl クラスを拡張する GLControlTask クラスのコードは次のとおりです。
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Threading.Tasks
Imports OpenTK
Imports OpenTK.Graphics
Imports OpenTK.Graphics.OpenGL
Public Class GLControlTask
Inherits GLControl
Private arm As Arm
Private rotator As ArcBall
Private glLoaded As Boolean = False
Private cameraAngleX As Single
Private cameraAngleY As Single
Private cameraAngleZ As Single
Private prevMouseX As Integer
Private prevMouseY As Integer
Private glMouseDown As Boolean
Private lightAngleX As Single
Private lightAngleY As Single
Private lightDistance As Single
'Perspective Attributes
Private eyeOffset As Vector3
Private boxRadius As Single
Private boxOffset As Vector3
Private isPerspective As Boolean
Private hasLighting As Boolean
Private hasFog As Boolean
Public Sub New()
arm = New Arm()
arm.loadFromXML()
'MsgBox(arm.ToString())
isPerspective = False
hasLighting = True
hasFog = False
eyeOffset.X = 0
eyeOffset.Y = 0
eyeOffset.Z = 1000.0F
lightDistance = 10000.0F
lightAngleX = 0.0F
lightAngleY = 0.0F
boxRadius = 2.5F
End Sub
Private Sub Me_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
glLoaded = True
GL.ClearColor(Color.Black)
rotator = New ArcBall(Me)
Me_Resize(Nothing, New EventArgs())
End Sub
Private Sub Me_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Resize
If glLoaded = False Then
Return
End If
GL.Viewport(0, 0, Me.Width, Me.Height)
rotator.windowResized()
Me.Invalidate()
End Sub
'PAINT CODE REMOVED
Private Sub On_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
glMouseDown = True
Me.MakeCurrent()
prevMouseX = e.X
prevMouseY = e.Y
rotator.mousePressed(e.X, e.Y)
End Sub
Private Sub Me_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
glMouseDown = False
End Sub
Private Sub Me_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If glMouseDown = False Then
Return
End If
If e.Button = MouseButtons.Left Then
rotator.mouseDragged(e.X, e.Y)
Me.Invalidate()
End If
prevMouseX = e.X
prevMouseY = e.Y
End Sub
Private Function deg2Rad(ByVal degrees As Double) As Double
Return degrees * Math.PI / 180
End Function
End Class