Debugging 3D Programs

Why am I staring at a black screen?

Every 3D programmer, no matter how experienced, asks themselves this question on a regular basis. Here are some answers:

You didn't draw anything. Put a print statement in your display code: is it actually being called?

You drew everything in black. C and Java will initialise your colors to all zero, which is black, if you forget to set them. Black objects on black background are hard to see.

A good test for either of these problems is to change the clear color to red.

You are looking in the wrong direction. The entire scene may be behind you, or perhaps a long way below. Change your viewpoint.

You haven't increased the far clip distance. In 3D programs you set the near and far clipping planes, which are distances from the viewpoint, Only those objects between the near and far distances will be rendered. If the far distance is 5 metres then nothing more than 5 metres away, no matter how big, will be drawn. Values of 1 and 1,000 for near and far work for most scenes.

An OpenGL error occurred before anything got drawn. You are checking for OpenGL errors at the end of each frame? If there is an error very early on, later drawing commands may be quietly ignored.

Why didn't it change?

You don't handle the event. Your event handler might not be registered or has a typo. Add a print statement "The button has been pressed!" to make sure it is working.

You forgot to force an update. Common for C programmers. Your program changes the values but you don't call glutPostRedisplay afterwards. Try resizing the window.

The change is too small to see. Are you working with the right coordinate system? Translating a building by 0.001 of a metre is very hard to detect. Try doubling the change, or even multiplying by ten.