Initialize an OpenTK::GraphicsContext from the foreign GDK context.
authorJarl Gullberg <jarl.gullberg@gmail.com>
Fri, 15 Sep 2017 09:51:11 +0000 (11:51 +0200)
committerJarl Gullberg <jarl.gullberg@gmail.com>
Fri, 15 Sep 2017 09:51:11 +0000 (11:51 +0200)
src/OpenTK.GLWidget/GLWidget.cs

index 53d318975da7b46100e9a89874d9e6f8ad1b72e6..db1833e03b36a7de7c93f0f319066633d247194a 100644 (file)
@@ -386,9 +386,14 @@ namespace OpenTK
                 _WindowInfo = XWindowInfoInitializer.Initialize(graphicsMode, this.Display.Handle, this.Screen.Number, widgetWindowHandle, this.Screen.RootWindow.Handle);
             }
 
-            // GraphicsContext
+            // Make the GDK GL context current
+            Context.MakeCurrent();
 
-            _GraphicsContext = new GraphicsContext(graphicsMode, _WindowInfo, GlVersionMajor, GlVersionMinor, GraphicsContextFlags);
+            // Create an OpenTK graphics context using the GdkGLContext as a foreign context
+            // Since the GDK context is already created and has been made current, we can retrieve its handle.
+            var gdkContextHandle = Factory.Default.CreateGetCurrentGraphicsContext()();
+
+            _GraphicsContext = new GraphicsContext(gdkContextHandle, _WindowInfo, null, GlVersionMajor, GlVersionMinor, GraphicsContextFlags);
             _GraphicsContext.MakeCurrent(_WindowInfo);
 
             if (GraphicsContext.ShareContexts)