Rediger

Del via


glStencilFunc function

The glStencilFunc function sets the function and reference value for stencil testing.

Syntax

void WINAPI glStencilFunc(
   GLenum func,
   GLint  ref,
   GLuint mask
);

Parameters

func

The test function. The following eight tokens are valid.

Value Meaning
GL_NEVER
Always fails.
GL_LESS
Passes if (ref & mask) < (stencil & mask).
GL_LEQUAL
Passes if (ref & mask) = (stencil & mask).
GL_GREATER
Passes if (ref & mask) > (stencil & mask).
GL_GEQUAL
Passes if (ref & mask) = (stencil & mask).
GL_EQUAL
Passes if (ref & mask) = (stencil & mask).
GL_NOTEQUAL
Passes if (ref & mask) ? (stencil & mask).
GL_ALWAYS
Always passes.

ref

The reference value for the stencil test. The ref parameter is clamped to the range [0, 2n 1], where n is the number of bitplanes in the stencil buffer.

mask

A mask that is ANDed with both the reference value and the stored stencil value when the test is done.

Return value

This function does not return a value.

Error codes

The following error codes can be retrieved by the glGetError function.

Name Meaning
GL_INVALID_ENUM
func was not one of the eight accepted values.
GL_INVALID_OPERATION
The function was called between a call to glBegin and the corresponding call to glEnd.

Remarks

Stenciling, like z-buffering, enables and disables drawing on a per-pixel basis. You draw into the stencil planes using OpenGL drawing primitives, then render geometry and images, using the stencil planes to mask out portions of the screen. Stenciling is typically used in multipass rendering algorithms to achieve special effects, such as decals, outlining, and constructive solid geometry rendering.

The stencil test conditionally eliminates a pixel based on the outcome of a comparison between the reference value and the value in the stencil buffer. The test is enabled by glEnable and glDisable with argument GL_STENCIL_TEST. Actions taken based on the outcome of the stencil test are specified with glStencilOp.

The func parameter is a symbolic constant that determines the stencil comparison function. It accepts one of the eight values shown above. The ref parameter is an integer reference value that is used in the stencil comparison. It is clamped to the range [0, 2n 1], where n is the number of bitplanes in the stencil buffer. The mask parameter is bitwise ANDed with both the reference value and the stored stencil value, with the ANDed values participating in the comparison.

If stencil represents the value stored in the corresponding stencil buffer location, the preceding list shows the effect of each comparison function that can be specified by func. Only if the comparison succeeds is the pixel passed through to the next stage in the rasterization process (see glStencilOp). All tests treat stencil values as unsigned integers in the range [0, 2n 1], where n is the number of bitplanes in the stencil buffer.

Initially, the stencil test is disabled. If there is no stencil buffer, no stencil modification can occur and it is as if the stencil test always passes.

The following functions retrieve information related to glStencilFunc:

glGet with argument GL_STENCIL_FUNC

glGet with argument GL_STENCIL_VALUE_MASK

glGet with argument GL_STENCIL_REF

glGet with argument GL_STENCIL_BITS

glIsEnabled with argument GL_STENCIL_TEST

Requirements

Requirement Value
Minimum supported client
Windows 2000 Professional [desktop apps only]
Minimum supported server
Windows 2000 Server [desktop apps only]
Header
Gl.h
Library
Opengl32.lib
DLL
Opengl32.dll

See also

glAlphaFunc

glBegin

glBlendFunc

glDepthFunc

glEnable

glEnd

glIsEnabled

glLogicOp

glStencilOp