The use of the stencil buffer is enabled with glEnable(GL_STENCIL_TEST) and controlled with the glStencilFunc() and glStencilOp() functions.
The glStencilFunc() function sets the comparison function used by stencil operations and also how the stencil buffer will be modified by stenciling operations.
The glStencilOp() specifies what actions are taken for the outcomes of various stencil test operations.