Setup correct class style for OpenGL
authorStefanos A. <stapostol@gmail.com>
Sat, 16 Nov 2013 21:38:17 +0000 (22:38 +0100)
committerStefanos A. <stapostol@gmail.com>
Sat, 16 Nov 2013 21:38:17 +0000 (22:38 +0100)
On Windows, we need to have a CS_OWNDC class style on windows with
OpenGL contexts attached. In Windows.Forms, we can set this via the
Control.CreateParams property. See
https://www.opengl.org/wiki/Creating_an_OpenGL_Context_(WGL)

Source/GLControl/GLControl.cs

index 9e9619a970f6cfd416a8c57eed86560aa5b8780c..b648a5e6ef47fa844c45b53c5a57b237a437ec62 100644 (file)
@@ -155,6 +155,30 @@ namespace OpenTK
 
         #region --- Protected Methods ---
 
+        /// <summary>
+        /// Gets the <c>CreateParams</c> instance for this <c>GLControl</c>
+        /// </summary>
+        protected override CreateParams CreateParams
+        {
+            get
+            {
+                const int CS_VREDRAW = 0x1;
+                const int CS_HREDRAW = 0x2;
+                const int CS_OWNDC = 0x20;
+                const int WS_CLIPCHILDREN = 0x02000000;
+                const int WS_CLIPSIBLINGS = 0x04000000;
+
+                CreateParams cp = base.CreateParams;
+                if (Configuration.RunningOnWindows)
+                {
+                    // Setup necessary class style for OpenGL on windows
+                    cp.ClassStyle |= CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
+                    cp.Style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
+                }
+                return cp;
+            }
+        }
+
         /// <summary>Raises the HandleCreated event.</summary>
         /// <param name="e">Not used.</param>
         protected override void OnHandleCreated(EventArgs e)