Search code examples
debuggingopengloutputlwjgl

Cannot get ARB debug output from LWJGL


I am trying to use the ARB_debug_output extension but I cannot get any output from it (intentionally incorrect shaders will not cause debug output). I'm guessing I have made a mistake using the extension.

I have set up my context with debug enabled using;

        ContextAttribs contextAtrributes = new ContextAttribs(3, 2) // Core OpenGL version 3.2
        .withForwardCompatible(true)
        .withProfileCore(true)
        .withDebug(true);

I check for the debug output extension using;

            ContextCapabilities caps = GLContext.getCapabilities();
        if ( caps.OpenGL32 )
            System.out.println("OpenGL version 3.2 supported");
        if ( caps.GL_ARB_debug_output )
            System.out.println("ARB_debug_output extension supported");

Which gives the following output;

OpenGL version 3.2 supported
ARB_debug_output extension supported

I setup a callback function to print the debug output using;

new ARBDebugOutputCallback();

After this I run my program using incorrect/wrong shaders etc that produce compiler/linker errors using glGetShaderInfoLog and glGetError but I do not receive debug information from the callback function.


Solution

  • You need to pass the ARBDebugOutputCallback instance to the glDebugMessageCallbackARB method, like so:

    glDebugMessageCallbackARB(new ARBDebugOutputCallback());
    

    This is equivalent to passing a function pointer in the C API.

    Note that there is no userParam argument; it is used internally by LWJGL to implement ARB_debug_output properly when there are multiple OpenGL contexts present. It's not necessary in Java anyway, you can pass per-instance data using the ARBDebugOutputCallback(Handler) constructor.