Home - GeirGrusom/ModGL GitHub Wiki

Welcome to the ModGL wiki!

ModGL is an OpenGL wrapper for .NET intended to easily facilitate unit testing by wrapping the OpenGL calls though interfaces. The interfaces are implemented by Platform.Invoke which uses Reflection.Emit to generate the OpenGL interfaces, so there should be little to no performance penalty.

Platform.Invoke also supports call monitoring, which allows ModGL to throw exceptions (when Debug flags is provided) when an OpenGL call fails. Since this is generated at run-time, there is no branching at all when Release flags is set.


ModGL is easy to initialize. You need to create an OpenGL context which can be provided by a ContextFactory. The re is a public static Instance that provides a factory instance.

Example (using Windows Forms)

var form = new Form();
var graphics = form.CreateGraphics();

var parameters = new ContextCreationParameters 
    Window = (long)form.Handle, 
    Device = (long)graphics.GetHdc() 

using(var context = ContextFactory.Instance.Create(parameters))
using(context.Bind()) // MakeCurrent
    var gl = context.CreateInterface<IOpenGL40>();
    // We have our context bound, and a OpenGL interface!
    // Ready to go!
⚠️ **GitHub.com Fallback** ⚠️