Skip to content

Instantly share code, notes, and snippets.

View NovemberDev's full-sized avatar
🌊
somewhere out there

NovemberDev

🌊
somewhere out there
View GitHub Profile

Guide to using OpenGL's GL.DebugMessageCallback()

When learning OpenGL, one of the most common sources of bugs you'll encounter is from performing OpenGL API calls with invalid arguments, performing them in the wrong order, or performing calls that assume some OpenGL state that differs from the actual state.

With most well-written C# APIs, you'd get an exception thrown the moment you do something you shouldn't. By default, this doesn't happen with OpenGL, but there are still ways to tell if there are errors:

The easy (but tedious) way

The common way to check for errors is to use GL.GetError() to check for errors, often with a helper method such as the following: