# How can I use ARB_debug_output with SDL on Windows?

I'm trying to port a small GL program that I've been working on from Linux to Windows. I have the following:

window_ = SDL_CreateWindow(...);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
glContext_ = SDL_GL_CreateContext(window_);
glewInit();
if (GLEW_ARB_debug_output)
{
glDebugMessageCallbackARB(&DebugCallback, nullptr);
}


I was surprised to find out that GLEW_ARB_debug_output evaluates to false. Could it be that ARB_debug_output not supported on Windows, with the latest drivers for my video card (an older Radeon HD540v)? Am I doing anything wrong? I thought this extension was rather old, and it would probably be supported everywhere by now.

Update: I added my SDL initialization code, as I needed to pass SDL_GL_CONTEXT_DEBUG_FLAG. Unfortunately, ARB_debug_output is still not supported.

Update: After initializing the context with the debug flag through SDL, I manually queried the available extensions (bypassing GLEW) and ARB_debug_output is not available! Again, could this not be supported on my implementation?

ARB_debug_output requires, I believe, the context to have been created with WGL_CONTEXT_DEBUG_BIT_ARB via wglCreateContextAttribs. That function is itself an extension, which means that GLEW probably cannot properly acquire the function pointers to the GLEW_ARB_debug_output functions because it will not have made use of that extension function to set the debug bit on the context.

You will probably need to manually set up the extension function pointers for GLEW_ARB_debug_output (like we had to do in the dark ages) after creating a context with wglCreateContextAttribs.

This chicken-and-egg issue with GLEW was noticed back in 2011 or so (ARB_debug_output is from 2010), but GLEW's change log doesn't make an obvious mention of a solution beyond mentioning when it acquired ARB_debug_output support.

• Thanks! I use SDL in my program, and your answer lead me to SDL_GL_CONTEXT_DEBUG_FLAG. Unfortunately, I still can't make it work :( I updated my question to reflect this. – Dan Nestor Jan 9 '14 at 18:21

### There are a couple of important things to note here:

1. AMD did not always implement ARB_debug_output. Technically, ARB_debug_output is an improved version of AMD's original extension: AMD_debug_output. Older AMD drivers lagged behind NV in adopting the ARB'ified version of AMD's own extension.

• Now here is where things get really funny: GL_KHR_debug is yet another improvement on the ARB extension. There are theoretically implementations of OpenGL that support neither AMD nor ARB's debug output but do support KHR_debug. At its core (no pun intended), however, the KHR extension re-uses the same function names, enums and constants (but without the ARB suffix).
2. This extension is generally only listed if you query the extension string while you are running in a debug context.

• More importantly, GLEW is rather stupid when it comes to querying extensions by name and uses glGetString (GL_EXTENSIONS), which is invalid in core contexts. The macros such as GLEW_ARB_debug_output reflect whether the extension is listed in the extensions string (which GLEW may not even be capable of querying if you are using a core context).

### I would suggest you initialize GLEW this way instead:

/**
* Tells GLEW not to use the extension string.
*
*   Instead, it determines if an extension is supported by actually trying to load it.
**/
glewExperimental = GL_TRUE;
glewInit ();

if (glDebugMessageCallbackARB != NULL) {
// Debug Output is supported, hooray!
}


By the way, the extension GL_KHR_debug has one other benefit that GL_ARB_debug_output does not. You can look for this extension by name (assuming you properly query the extension string) whether you have a debug context or not. A non-debug context created by an implementation of OpenGL that supports debug output is guaranteed to list this extension, whereas it may not list GL_ARB_debug_output.

• It's the same :( Even with glewExperimental set to true, the pointer is still null. – Dan Nestor Jan 10 '14 at 12:24

Your code should work as it is.

In general, all you need to do is set the debug flag before creating the context and then query the extension.

The code I'm currently using (SDL+GLEW; error checking omitted for brevity):

// Get the current context flags and add the debug flag
// (so we don't accidentally reset any default flags)
int contextFlags = 0;
SDL_GL_GetAttribute(SDL_GL_CONTEXT_FLAGS, &contextFlags);
contextFlags |= SDL_GL_CONTEXT_DEBUG_FLAG;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, contextFlags);

// Create window and context
SDL_Window* window = SDL_CreateWindow(...);
void* context = SDL_GL_CreateContext(window);

// Init GLEW
glewInit();

// Set debug callback function
if (GLEW_ARB_debug_output) {
glDebugMessageCallbackARB(&DebugCallbackARB, nullptr);
}
else if (GLEW_AMD_debug_output) {
glDebugMessageCallbackAMD(&DebugCallbackAMD, nullptr);
}


So, the only real difference I can see is that you don't check for GLEW_AMD_debug_output. I have actually never tried this on a system which didn't have GLEW_ARB_debug_output set, so I'd be interested to hear if this fixes it for you (if this is still relevant after 2.5 years).

Note that the callback functions have slightly different signatures:

void DebugCallbackARB(GLenum source​,
GLenum type​,
GLuint id​,
GLenum severity​,
GLsizei length​,
const GLchar* message​,
const GLvoid* userParam​);

void DebugCallbackAMD(GLuint id,
GLenum category,
GLenum severity,
GLsizei length,
const GLchar* message,
GLvoid* userParam);