OpenGL Programming/Debugging

Mesa

edit

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

Error reporting

edit

OpenGL uses glGetError() to report errors:

	switch (glGetError()) {
	case GL_NO_ERROR:
		cerr << "GL_NO_ERROR" << endl;
		break;
	case GL_INVALID_ENUM:
		cerr << "GL_INVALID_ENUM" << endl;
		break;
	case GL_INVALID_VALUE:
		cerr << "GL_INVALID_VALUE" << endl;
		break;
	case GL_INVALID_OPERATION:
		cerr << "GL_INVALID_OPERATION" << endl;
		break;
	case GL_INVALID_FRAMEBUFFER_OPERATION:
		cerr << "GL_INVALID_FRAMEBUFFER_OPERATION" << endl;
		break;
	case GL_OUT_OF_MEMORY:
		cerr << "GL_OUT_OF_MEMORY" << endl;
		break;
	}

Stencil buffer

edit

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

Links

edit

< OpenGL Programming

Browse & download complete code