From c32ffbbc088e664098ad6da62c6ef2d63b152a9d Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Wed, 2 Dec 2020 15:52:19 +0100 Subject: [PATCH] get glwpfcontrol to work --- .../Preview/ModelPreview.vb | 64 ++++++++++--------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.vb index d3c7165..0172db4 100644 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.vb +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.vb @@ -128,28 +128,23 @@ Namespace PreviewN Me.SuspendLayout() InitializeComponent() - DoubleBuffered = True 'glControl1 - Me.glControl1 = New Wpf.GLWpfControl - Me.glControlHost = New ElementHost - Me.glControlHost.BackColor = Color.Black - Me.glControlHost.Name = "glControl1" - Me.glControlHost.Anchor = AnchorStyles.Left Or AnchorStyles.Top Or AnchorStyles.Right Or AnchorStyles.Bottom - Me.glControlHost.Location = New Point(0, 0) - Me.glControlHost.Size = Me.ClientSize - Me.glControlHost.MinimumSize = New Size(600, 120) - Me.glControlHost.TabIndex = 0 - Me.glControlHost.TabStop = False - Me.glControlHost.Child = glControl1 - Me.Controls.Add(Me.glControlHost) - Me.ResumeLayout(False) - - 'RenderTimer.SynchronizingObject = Nothing - Scaling = scale - - 'Toolkit.Init() + Dim glControl1 As New GLWpfControl + glControl1.IsEnabled = False + Dim glControlHost = New ElementHost + glControlHost.BackColor = Color.Black + glControlHost.Name = "glControl1" + glControlHost.Anchor = AnchorStyles.Left Or AnchorStyles.Top Or AnchorStyles.Right Or AnchorStyles.Bottom + glControlHost.Location = New Point(0, 0) + glControlHost.Size = Me.ClientSize + glControlHost.MinimumSize = New Size(600, 120) + glControlHost.TabIndex = 0 + glControlHost.TabStop = False + ResumeLayout(False) + Me.glControl1 = glControl1 + Me.glControlHost = glControlHost Dim controlSettings As New GLWpfControlSettings With { @@ -157,9 +152,13 @@ Namespace PreviewN .GraphicsProfile = Windowing.Common.ContextProfile.Compatability } glControl1.Start(controlSettings) - AddHandler glControl1.MouseWheel, AddressOf glControl1_Wheel - ProjMatrix = Matrix4.CreatePerspectiveFieldOfView(FOV, glControl1.Width / glControl1.Height, 100.0F, 100000.0F) - glControlHost.Enabled = True + + glControlHost.Child = glControl1 + Controls.Add(glControlHost) + + Scaling = scale + + ProjMatrix = Matrix4.CreatePerspectiveFieldOfView(FOV, glControlHost.Width / glControlHost.Height, 100.0F, 100000.0F) MyCamera.SetCameraMode(CameraMode.FLY, camMtx) MyCamera.UpdateMatrix(camMtx) @@ -179,10 +178,15 @@ Namespace PreviewN Public Sub UpdateView() If glControl1.IsEnabled Then - glControlHost.Invoke(Sub() glControlHost.Invalidate()) + Invoke(Sub() InvalidateGL()) End If End Sub + Public Sub InvalidateGL() + glControl1.InvalidateVisual() + glControlHost.Invalidate() + End Sub + Public Function AddModel(obj As Object3D) As Renderer Dim rndr As New Renderer(obj) AddModel(rndr) @@ -194,9 +198,9 @@ Namespace PreviewN End Sub Public Sub HandlesOnShown(sender As Object, e As EventArgs) Handles MyBase.Shown - glControlHost.Enabled = True + glControl1.IsEnabled = True RenderModels() - glControlHost.Invalidate() + InvalidateGL() End Sub Public Sub RenderModels() @@ -212,7 +216,7 @@ Namespace PreviewN End If End Sub - Private Sub glControl1_Load(sender As Object, e As EventArgs) Handles glControl1.Loaded + Private Sub glControl1_Load() Handles glControl1.Ready GL.Enable(EnableCap.Blend) GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha) @@ -265,14 +269,14 @@ Namespace PreviewN 'glControl1.Context.Update(glControl1.WindowInfo) GL.Viewport(0, 0, glControlHost.Width, glControlHost.Height) ProjMatrix = Matrix4.CreatePerspectiveFieldOfView(FOV, glControlHost.Width / glControlHost.Height, 100.0F, 100000.0F) - glControlHost.Invalidate() + InvalidateGL() End Sub - Private Sub glControl1_Wheel(sender As Object, e As Windows.Input.MouseWheelEventArgs) + Private Sub glControl1_Wheel(sender As Object, e As Windows.Input.MouseWheelEventArgs) Handles glControl1.MouseWheel MyCamera.ResetMouseStuff() MyCamera.UpdateCameraMatrixWithScrollWheel(CInt(Math.Truncate(e.Delta * (If(IsShiftPressed, 3.5F, 1.5F)))), camMtx) savedCamPos = MyCamera.Position - glControlHost.Invalidate() + InvalidateGL() End Sub Private Sub glControl1_MouseDown(ByVal sender As Object, ByVal e As Windows.Input.MouseButtonEventArgs) Handles glControl1.MouseDown @@ -292,7 +296,7 @@ Namespace PreviewN Else MyCamera.UpdateCameraMatrixWithMouse(e.X, e.Y, camMtx) End If - glControlHost.Invalidate() + InvalidateGL() End If End Sub