glDepthFunc

The glDepthFunc function specifies the value used for depth-buffer comparisons.

void glDepthFunc(
  GLenum func);

Parameters

  • func
    Specifies the depth-comparison function. The following symbolic constants are accepted.
    Symbolic Constant Meaning
    GL_NEVER Never passes.
    GL_LESS Passes if the incoming z value is less than the stored z value. This is the default value.
    GL_LEQUAL Passes if the incoming z value is less than or equal to the stored z value.
    GL_EQUAL Passes if the incoming z value is equal to the stored z value.
    GL_GREATER Passes if the incoming z value is greater than the stored z value.
    GL_NOTEQUAL Passes if the incoming z value is not equal to the stored z value.
    GL_GEQUAL Passes if the incoming z value is greater than or equal to the stored z value.
    GL_ALWAYS Always passes.

Remarks

The glDepthFunc function specifies the function used to compare each incoming pixel z value with the z value present in the depth buffer. The comparison is performed only if depth testing is enabled. (See glEnable with the argument GL_DEPTH_TEST.)

Initially, depth testing is disabled.

The following functions retrieve information related to glDepthFunc:

glGet with argument GL_DEPTH_FUNC

glIsEnabled with argument GL_DEPTH_TEST

Error Codes

The following are the error codes generated and their conditions.

Error code Condition
GL_INVALID_ENUM func was not an accepted value.
GL_INVALID_OPERATION glDepthFunc was called between a call to glBegin and the corresponding call to glEnd.

Requirements

**  Windows NT/2000:** Requires Windows NT 3.5 or later.
**  Windows 95/98:** Requires Windows 95 or later. Available as a redistributable for Windows 95.
**  Header:** Declared in Gl.h.
**  Library:** Use Opengl32.lib.

See Also

glBegin, glDepthRange, glEnable, glEnd, glGet, glIsEnabled