Last active
December 26, 2024 04:20
-
-
Save NepNet/62d0af952f39799ba45cf01770752542 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Runtime.InteropServices; | |
| using Gtk; | |
| using OpenToolkit.Graphics.OpenGL4; | |
| //this is just a template, if you encounter incorrect drawing when resizing you can disable double buffering on the top level window for the widget, I couldn't find a better fix | |
| //and will work only on Linux, to fix that you could change the bindings context that will be loaded with one that workd on another platforms like glfw | |
| namespace OpenToolkit | |
| { | |
| public class GLWidget : GLArea | |
| { | |
| private static bool _bindingsLoaded; | |
| public GLWidget() { } | |
| public GLWidget(GLArea area) : base(area.Handle) { } | |
| public GLWidget(IntPtr handle) : base(handle) { } | |
| protected override void OnRealized() | |
| { | |
| base.OnRealized(); | |
| MakeCurrent(); | |
| if (!_bindingsLoaded) | |
| { | |
| GL.LoadBindings(new GLXBindingsContext()); | |
| } | |
| } | |
| protected override void OnResize(int width, int height) | |
| { | |
| base.OnResize(width, height); | |
| QueueRender(); | |
| } | |
| } | |
| public class GLXBindingsContext : IBindingsContext | |
| { | |
| public IntPtr GetProcAddress(string procName) | |
| { | |
| return glXGetProcAddress(procName); | |
| } | |
| [DllImport("libGL", CharSet = CharSet.Ansi)] | |
| private static extern IntPtr glXGetProcAddress(string procName); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment