Next: 4 Conclusion Up: OpenGL and X Previous: 3.2 Timeouts

4 Debugging Tips

As well as demonstrating the use of widgets with OpenGL, paperplane also demonstrates detection of OpenGL errors for debugging purposes. Some debugging code has been added to the bottom of paperplane's draw function to test for any OpenGL errors. A correct OpenGL program should not generate any OpenGL errors, but while debugging it is helpful to check explicitly for errors. A good time to check for errors is at the end of each frame. Errors in OpenGL are not reported unless you explicitly check for them, unlike X protocol errors which are always reported to the client.

OpenGL errors are recorded by setting ``sticky'' flags. Once an error flag is set, it will not be cleared until glGetError is used to query the error. An OpenGL implementation may have several error flags internally that can be set (since OpenGL errors might occur in different stages of the OpenGL rendering pipeline). When you look for errors, you should call glGetError repeatedly until it returns GL_NO_ERROR indicating that all of the error flags have been cleared.

The OpenGL error model is suited for high performance rendering, since error reporting does not slow down the error-free case. Because OpenGL errors should not be generated by bug-free code, you probably want to remove error querying from your final program since querying errors will slow down your rendering speed.

When an OpenGL error is generated, the command which generated the error is not recorded, so you may need to add more error queries into your code to isolate the source of the error.

The gluErrorString routine in the OpenGL Utility library (GLU) converts an OpenGL error number into a human readable string and helps you output a reasonable error message.


mjk@asd.sgi.com
Wed Oct 19 18:08:51 PDT 1994