Mesa is the open source library on Linux that provides the OpenGL implementation for programs. The Mesa library installed by Ubuntu can be pretty old. For example, my Mesa library showed support for the archaic OpenGL 2.1 standard.
Thankfully, there is a PPA that provides updated Mesa libraries. Updating is easy:
$ sudo add-apt-repository ppa:oibaf/graphics-drivers
$ sudo apt-get update
$ sudo apt-get dist-upgrade
Remember to reboot the computer after this update. I found that Mesa supported OpenGL 3.0 after this update! 😄
Tried with: Mesa 11.1 and Ubuntu 14.04
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