Enable Depth Buffering

From OpenGL Wiki
Revision as of 18:36, 30 April 2006 by Marco (talk | contribs) (Enable Depthbuffering moved to Enable Depth Buffering)
Jump to: navigation, search

Your application needs to do at least the following to get depth buffering to work:

  1. Ask for a depth buffer when you create your window.
  2. Place a call to glEnable (GL_DEPTH_TEST) in your program's initialization routine, after a context is created and made current.
  3. Ensure that your zNear and zFar clipping planes are set correctly and in a way that provides adequate depth buffer precision.
  4. Pass GL_DEPTH_BUFFER_BIT as a parameter to glClear, typically bitwise OR'd with other values such as GL_COLOR_BUFFER_BIT.

There are a number of OpenGL example programs available on the Web, which use depth buffering. If you're having trouble getting depth buffering to work correctly, you might benefit from looking at an example program to see what is done differently. This FAQ contains links to several web sites that have example OpenGL code.