In OpenGL, multiple types of errors might have occurred by the time you check for them. The errors are stored using the data type
GL_NO_ERROR always has the value
0 and you need to call
glGetError() multiple times (one for each error that has occurred) until it returns
GL_NO_ERROR. A general rule of thumb is to check for error at least once in a rendering cycle.
The standard OpenGL errors I found defined on my system:
#define GL_NO_ERROR 0 #define GL_INVALID_ENUM 0x0500 #define GL_INVALID_VALUE 0x0501 #define GL_INVALID_OPERATION 0x0502 #define GL_STACK_OVERFLOW 0x0503 #define GL_STACK_UNDERFLOW 0x0504 #define GL_OUT_OF_MEMORY 0x0505
In addition to these standard values, OpenGL extensions could introduce their own error types.
Putting all this together, we can write a simple function named
CheckGLError that checks for errors and if any, then prints them out:
Note: If you are using GLU, then the
gluErrorString function can be used to convert OpenGL error to a string.
Tried with: Mesa 10.1.3 and Ubuntu 14.04