Context & stateGL 1.0
glEnable
Switches on a fixed-function feature such as depth testing, blending or face culling.
Signature
void glEnable(GLenum cap);
How it works
Many pipeline stages that are not shaders — depth test, blending, culling… — are toggled with glEnable/glDisable. They stay in that state until you change them, for every following draw.
Most are off by default. A 3D scene without glEnable(GL_DEPTH_TEST) draws triangles in submission order, so far objects can appear on top of near ones.
Parameters
capGLenum
The capability to enable.
Common values
- GL_DEPTH_TEST
- Hide fragments behind closer ones using the depth buffer.
- GL_BLEND
- Mix fragment colors with what is already in the framebuffer (transparency).
- GL_CULL_FACE
- Skip triangles facing away from the camera.
- GL_STENCIL_TEST
- Accept or reject fragments using the stencil buffer.
- GL_SCISSOR_TEST
- Only draw inside the rectangle set by glScissor.
- GL_POLYGON_OFFSET_FILL
- Apply the depth offset from glPolygonOffset.
- GL_FRAMEBUFFER_SRGB
- Convert linear colors to sRGB when writing to an sRGB framebuffer.
- GL_MULTISAMPLE
- Use MSAA when the framebuffer has multiple samples (on by default).
- GL_DEBUG_OUTPUT / GL_DEBUG_OUTPUT_SYNCHRONOUS
- Send driver messages to the debug callback (synchronously = on the calling thread, right away).
- GL_PROGRAM_POINT_SIZE
- Let the vertex shader set gl_PointSize.
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_ENUM
- cap is not a known capability.
Example
example.cpp
1glEnable(GL_DEPTH_TEST);
2glEnable(GL_CULL_FACE);
3glEnable(GL_BLEND);
4glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);