views:

1615

answers:

5

I find that a lot of the time, OpenGL will show you it failed by not drawing anything. I'm trying to find ways to debug OpenGL programs, by inspecting the transformation matrix stack and so on. What is the best way to debug OpenGL? If the code looks and feels like the vertices are in the right place, how can you be sure they are?

+5  A: 

There is not straight answer. It all depends on what you are trying to understand. Since OpenGL is state machine, sometime it does not do what you expect as required state is not set or things like that.

In general, use tools like glTrace / glIntercept (to look at OpenGL call trace), gDebugger (to visualize textures, shaders, OGL state etc.) and paper/pencil :). Sometimes it helps to understand how you have setup camera and where it is looking, what is being clipped etc. I have personally relied to last more than previous two approaches. But when I can argue that depth is wrong then it helps to look at trace. gDebugger is also the only tool that can be used effectively for profiling and optimization your OpenGL app.

Apart from this tool, most of the time it is the math that people get it wrong and it can't be understood using any tool. Post on OpenGL.org newgroup for code specific comments, you will be never disappointed.

Hope this answers your question!

Ketan
Just seconding gDebugger. There's a trial version so give it a go.
Greg Whitfield
There is Academic license too, if you quality
Ketan
+4  A: 

GLIntercept is your best bet. From their web page:

  • Save all OpenGL function calls to text or XML format with the option to log individual frames.
  • Free camera. Fly around the geometry sent to the graphics card and enable/disable wireframe/backface-culling/view frustum render
  • Save and track display lists. Saving of the OpenGL frame buffer (color/depth/stencil) pre and post render calls. The ability to save the "diff" of pre and post images is also available.
David Segonds
+1  A: 

There is also the free glslDevil: http://www.vis.uni-stuttgart.de/glsldevil/

It allows you to debug glsl shaders extensively. It also shows failed OpenGL calls.

However it's missing features to inspect textures and off screen buffers.

heeen
+1  A: 

For those on Mac, the buit in OpenGL debugger is great as well. It lets you inspect buffers, states, and helps in finding performance issues.

sjmulder
A: 

You're screwed.

ponce
What kind of answer should it be?
Luca
GLIntercept is useful but limited.I've tried gDebugger and it relies on NVIDIA on obviously old and broken drivers while on ATI... well, didn't worked.AMD release recently the GL_AMD_debug_output extension, which can catch missing glEnd() or simple OpenGL misuse but won't be useful with a real-life nasty driver bug.Likely you end up running into an undocumented bug that make the driver crash or silently output wrong data, and then you're screwed.Maddening stuff.
ponce