Depth, blending & cullingGL 1.1
glPolygonOffset
Pushes polygon depth values slightly, to avoid z-fighting and shadow acne.
Signature
void glPolygonOffset(GLfloat factor, GLfloat units);
How it works
When two surfaces have almost the same depth (a decal on a wall, or a surface compared with its own shadow map), rounding makes them flicker — z-fighting. Polygon offset adds a small bias to the depth of what you draw next. The offset is factor × (depth slope of the polygon) + units × (smallest depth step).
It only applies after glEnable(GL_POLYGON_OFFSET_FILL).
Parameters
factorGLfloat
Scales with how steep the polygon is relative to the camera. Typical: 1.0–4.0.
unitsGLfloat
Constant offset in depth-buffer steps. Typical: 1.0–4.0.
Example
example.cpp
1// shadow pass
2glEnable(GL_POLYGON_OFFSET_FILL);
3glPolygonOffset(2.0f, 4.0f);
4renderSceneDepthOnly();
5glDisable(GL_POLYGON_OFFSET_FILL);