Depth Buffer and Perspective Rendering

From OpenGL.org
Jump to: navigation, search

Make sure the zNear and zFar clipping planes are specified correctly in your calls to glFrustum() or gluPerspective().

A mistake many programmers make is to specify a zNear clipping plane value of 0.0 or a negative value which isn't allowed. Both the zNear and zFar clipping planes are positive (not zero or negative) values that represent distances in front of the eye.

Specifying a zNear clipping plane value of 0.0 to gluPerspective() won't generate an OpenGL error, but it might cause depth buffering to act as if it's disabled. A negative zNear or zFar clipping plane value would produce undesirable results.

A zNear or zFar clipping plane value of zero or negative, when passed to glFrustum(), will produce an error that you can retrieve by calling glGetError(). The function will then act as a no-op.