Depth, blending & cullingGL 1.0

glCullFace

Chooses which faces are discarded when face culling is enabled.

Signature

void glCullFace(GLenum mode);

How it works

On a closed mesh, the triangles facing away from the camera are always hidden behind the ones facing it. Culling skips them before rasterization, saving roughly half the fragment work. Whether a triangle is front or back is decided by its winding (see glFrontFace).

012012counter-clockwise: frontclockwise: back, culled
Winding is the order the vertices appear in on screen. With the default glFrontFace(GL_CCW), the counter-clockwise triangle faces the camera; the clockwise one shows its back, and glCullFace(GL_BACK) skips it. Turning a triangle around flips its winding, which is how culling knows.

Parameters

modeGLenum

Which side to discard.

Common values

GL_BACK
Discard back faces (default).
GL_FRONT
Discard front faces — used in shadow passes to reduce peter-panning.
GL_FRONT_AND_BACK
Discard all polygons (lines and points still draw).

Example

example.cpp
1glEnable(GL_CULL_FACE);
2glCullFace(GL_BACK);
3glFrontFace(GL_CCW);
Official Khronos documentation