Difference between revisions of "Example/OpenGL Error Testing with Message Callbacks"

From OpenGL Wiki
Jump to navigation Jump to search
(Add GLAPIENTRY, required on Windows for correct calling convention)
 
Line 2: Line 2:
  
 
<source lang=cpp>
 
<source lang=cpp>
void MessageCallback( GLenum source,
+
void GLAPIENTRY
                      GLenum type,
+
MessageCallback( GLenum source,
                      GLuint id,
+
                GLenum type,
                      GLenum severity,
+
                GLuint id,
                      GLsizei length,
+
                GLenum severity,
                      const GLchar* message,
+
                GLsizei length,
                      const void* userParam )
+
                const GLchar* message,
 +
                const void* userParam )
 
{
 
{
 
   fprintf( stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n",
 
   fprintf( stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n",
Line 17: Line 18:
 
// During init, enable debug output
 
// During init, enable debug output
 
glEnable              ( GL_DEBUG_OUTPUT );
 
glEnable              ( GL_DEBUG_OUTPUT );
glDebugMessageCallback( (GLDEBUGPROC) MessageCallback, 0 );
+
glDebugMessageCallback( MessageCallback, 0 );
 
</source>
 
</source>
 
<noinclude>[[Category:Example Code]]</noinclude>
 
<noinclude>[[Category:Example Code]]</noinclude>

Latest revision as of 10:32, 10 May 2018

A simple example showing how to utilize debug message callbacks (e.g. for detecting OpenGL errors):

void GLAPIENTRY
MessageCallback( GLenum source,
                 GLenum type,
                 GLuint id,
                 GLenum severity,
                 GLsizei length,
                 const GLchar* message,
                 const void* userParam )
{
  fprintf( stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n",
           ( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ),
            type, severity, message );
}

// During init, enable debug output
glEnable              ( GL_DEBUG_OUTPUT );
glDebugMessageCallback( MessageCallback, 0 );