Depth, blending & cullingGL 1.0

glDepthFunc

Chooses the comparison that decides whether a fragment passes the depth test.

Signature

void glDepthFunc(GLenum func);

How it works

With GL_DEPTH_TEST enabled, every fragment's depth is compared with the value already stored in the depth buffer. If the comparison passes, the fragment is drawn (and its depth stored); otherwise it is discarded.

The default GL_LESS means "closer wins". You change it for special passes — GL_LEQUAL lets a skybox drawn at exactly depth 1.0 pass against a cleared buffer.

Parameters

funcGLenum

Comparison between the NEW fragment depth and the STORED depth.

Common values

GL_LESS
Pass if closer (default).
GL_LEQUAL
Pass if closer or equal — skyboxes, multi-pass rendering.
GL_GREATER / GL_GEQUAL
Reversed-Z setups.
GL_ALWAYS / GL_NEVER
Always / never pass.
GL_EQUAL / GL_NOTEQUAL
Exact matches (depth pre-pass).

Example

example.cpp
1glDepthFunc(GL_LEQUAL);
2drawSkybox();
3glDepthFunc(GL_LESS);
Official Khronos documentation