You would enable writing to the stencil buffer by doing a generic function, like
graphicsEnable(STENCIL_BUFFER);
then, you would, in most cases, clear the stencil buffer before you start using it.
graphicsClear(STENCIL_BUFFER);
Following, since you're in stencil mode, any showimgs, anything that would normally be drawn to the draw buffer is now drawn to the stencil buffer. You set an operation using
setStencilOp(STENCILOP);
and could choose from the following operations:
NPC Code:
STENCILOP_KEEP
STENCILOP_ZERO
STENCILOP_REPLACE
STENCILOP_INVERT
STENCILOP_INCR
STENCILOP_DECR
Finally, after creating a proper stencil buffer, you could then test against it when drawing images:
stencilTestFunc(STENCILTEST);
NPC Code:
STENCILTEST_NEVER
STENCILTEST_LESS
STENCILTEST_LESSEQUAL
STENCILTEST_EQUAL
STENCILTEST_GREATER
STENCILTEST_GREATEREQUAL
STENCILTEST_NOTEQUAL
STENCILTEST_ALWAYS
Setting a reference value could just be something like
stencilSetReference(int);
Could be used for tons of stuff.. Parallax scrolling backgrounds, reflections of sky images in water, reflections of players in water.. Tons of very interesting uses if it's put to good use.
If you've ever used the stencil buffer in an OpenGL application, you'd be familiar with how to use it and you'd see a bunch of potentional, too