Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OpenGL Error handling
Pretty sure I have this elsewhere on this forum but adding it again for students to see.

OpenGLES2.0 has limited error handling
GLint err = glGetError();

Only gives you an indication that an error happend once, sometime ago... you need to step back and  find it

Its far easier to check an error when it happens, and OpenGLES3.0 allows that. You need to install some libs, your system may not need all of them but best to try and install them.

sudo apt-get install libglx-mesa0-dbgsym libglapi-mesa-dbgsym libgl1-mesa-dri-dbgsym

Also as this is also an extension it will also need libdl added so add dl to your binary libs it shouldn't need to be installed it should be onboard

Next you need a small callback function somewhere in your code but you need to set that up I use this, which is the actual callback and the init function, this lives in my main.cpp file and is called after openGL is initialised.
My sincere thanks tomy collegue Phil de Groot for working this out, its proved very helpful.

#include <csignal> //Raise and SIGTRAP constants.
#include <GLES2/gl2ext.h>

void OpenGLErrorCallbackHandler(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
    // try to stop the jetson complaining
    if (id != 0x00020092) // this seems to stop the strange recompile error but not an issue for Pi, confused!!
        switch (severity)
        { // we can choose to ignore most of the minor error reports, here we just focus on high and med

            std::cout << "OpenGL High/Med Error: " << message << std::endl;
            //Set a hard-coded breakpoint for only the error that we encounter.
            static bool onlyBreakOnFirst = true;
            if (onlyBreakOnFirst)
                onlyBreakOnFirst = false;

            //        std::cout << "OpenGL Low/Notice Warning: " << message << std::endl;
            break; //Ignore.
void InstallOpenGLErrorCallback()
    if (!(peglDebugMessageControlKHR != 0)) {
        printf("failed to eglGetProcAddress eglDebugMessageControlKHR\n");
        raise(SIGTRAP); //Be sure that we know about this.
    else {
        peglDebugMessageControlKHR(OpenGLErrorCallbackHandler, nullptr);
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's 


Forum Jump:

Users browsing this thread: 1 Guest(s)