OpenGL Programming/Debugging

= Mesa =

If you are using the Mesa OpenGL implementation you can set the following environment variables:
 * LIBGL_ALWAYS_SOFTWARE=1 : use the software implementation, without using the graphic card at all. This help when:
 * you suspect a bug in a driver,
 * you want to try an alternative implementation (as if you were using a different graphic card),
 * you want to check whether a graphic glitch is due to unitialized memory or to a programming mistake
 * MESA_DEBUG=1 : will output diagnostic messages in erroneous situations (e.g. assigning a uniform when the program is not linked)

See also Mesa's debugging and environment variables pages.

= Common mistakes =

If you manually draw lines or triangles, and nothing appears:
 * check that your 4th coordinate is 1 and not 0
 * check that you properly set glEnableVertexAttribArray / glBindBuffer / glVertexAttribPointer
 * double-check that you used the right variables (bad copy/paste...) - avoid global variables to help this
 * triple-check your  calls, including the type (3fv, 4fv...) - OpenGL is unforgiving and silent
 * beware that glDrawElements' 4th and last parameter is expressed in byte offset from the start, not in number of elements from the start, even when working with IBOs

= Error reporting =

OpenGL uses glGetError to report errors:

= Stencil buffer =

For tips on how to debug the stencil buffer, you can check the Stencil buffer section.

= Links =


 * Debugging of Shaders in the GLSL wikibooks (about debugging with colors)
 * Debugging Android NDK for debugging OpenGL NDK application on Android