Skip to content

Instantly share code, notes, and snippets.

@NepNet
Last active December 26, 2024 04:20
Show Gist options
  • Select an option

  • Save NepNet/62d0af952f39799ba45cf01770752542 to your computer and use it in GitHub Desktop.

Select an option

Save NepNet/62d0af952f39799ba45cf01770752542 to your computer and use it in GitHub Desktop.
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