Depth, blending & cullingGL 1.0
glClearDepth
Sets the value glClear writes into the depth buffer (1.0, the far plane, by default).
Signature
void glClearDepth(GLdouble depth);
How it works
With the default glDepthFunc(GL_LESS), the buffer must start at the farthest value, 1.0, so that anything drawn is closer and passes. You only change it when you reverse the depth test: with GL_GREATER (reversed Z), clear to 0.0 instead.
The pair has to agree. Clearing to 0.0 with GL_LESS left on makes every fragment fail, and only the background is visible.
Parameters
depthGLdouble
The clear value, clamped to [0, 1]. Default 1.0.
Tips & pitfalls
The clear respects
glDepthMask: with depth writes off, the depth buffer is not cleared.
Example
example.cpp
1// reversed Z
2glClearDepth(0.0);
3glDepthFunc(GL_GREATER);
4glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);