OpenGL Programming/Debugging

From Wikibooks, open books for an open world
Jump to: navigation, search


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[edit]

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 glUniform* calls, including the type (3fv, 4fv...) - OpenGL is unforgiving and silent
  • beware that glDrawElements' 4th and last parameter (indices) is expressed in byte offset from the start, not in number of elements from the start, even when working with IBOs

Stencil buffer[edit]

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


< OpenGL Programming

Browse & download complete code