[ Previous | Next | Contents | Glossary | Home | Search ]
OpenGL 1.1 for AIX: Reference Manual

glStencilFunc Subroutine

Purpose

Sets function and reference values for stencil testing.

Library

OpenGL C bindings library: libGL.a

C Syntax

void glStencilFunc(GLenum Function, 
     GLint Reference,
     GLuint Mask)

Parameters

Function Specifies the test function. Eight tokens are valid:
  • GL_NEVER
  • GL_LESS
  • GL_LEQUAL
  • GL_GREATER
  • GL_GEQUAL
  • GL_EQUAL
  • GL_NOTEQUAL
  • GL_ALWAYS
Reference Specifies the reference value for the stencil test. Reference is clamped to the range [0,2n-1], where n is the number of bit planes in the stencil buffer.
Mask Specifies a mask that is ANDed with both the reference value and the stored stencil value when the test is done.

Description

Stenciling, like z-buffering, enables and disables drawing on a per-pixel basis. You draw into the stencil planes using GL drawing primitives, and 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 the glEnable and glDisable subroutines with the GL_STENCIL argument. Actions taken based on the outcome of the stencil test are specified with the glStencilOp subroutine.

The Function parameter is a symbolic constant that determines the stencil comparison function. It accepts one of the eight following values. The Reference 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 bit planes 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 following list shows the effect of each comparison function that can be specified by the Function parameter. Only if the comparison succeeds is the pixel passed through to the next stage in the rasterization process. (See the glStencilOp subroutine for information on setting stencil test actions.) All tests treat stencil values as unsigned integers in the range [0,2n-1], where n is the number of bit planes in the stencil buffer.

The following values are accepted by the Function parameter:

GL_NEVER Always fails.
GL_LESS Passes if ( Reference & Mask ) is less than ( stencil & Mask ).
GL_LEQUAL Passes if ( Reference & Mask ) is less than or equal to ( stencil & Mask ).
GL_GREATER Passes if ( Reference & Mask ) is greater than ( stencil & Mask ).
GL_GEQUAL Passes if ( Reference & Mask ) is greater than or equal to ( stencil & Mask ).
GL_EQUAL Passes if ( Reference & Mask ) is equal to ( stencil & Mask ).
GL_NOTEQUAL Passes if ( Reference & Mask ) is not equal to ( stencil & Mask ).
GL_ALWAYS Always passes.

Notes

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.

Errors

GL_INVALID_ENUM Function is not one of the eight accepted values.
GL_INVALID_OPERATION The glStencilFunc subroutine is called between a call to glBegin and the corresponding call to glEnd.

Associated Gets

Associated gets for the glStencilFunc subroutine are as follows. (See the glGet subroutine.)

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.

Files

/usr/include/GL/gl.h Contains C language constants, variable type definitions, and ANSI function prototypes for OpenGL.

Related Information

The glAlphaFunc subroutine, glBegin or glEnd subroutine, glBlendFunc subroutine, glDepthFunc subroutine, glEnable or glDisable subroutine, glLogicOp subroutine, glStencilOp subroutine.

OpenGL Overview.


[ Previous | Next | Contents | Glossary | Home | Search ]