I’m trying to understand an example that uses the stencil mask, but end up with the wrong numbers. Here’s the example:
For example, it may be useful to draw a convex polyhedra such that
(assuming the stencil bufer is cleared to the binary value 1010):
- front-facing polygons that pass the depth test set stencil bit 0
- front-facing polygons that fail the depth test zero stencil bit 1
- back-facing polygons that pass the depth test set stencil bit 2
- back-facing polygons that fail the depth test zero stencil bit 3
This could be accomplished in a single rendering pass using:
[quote]
glStencilMask(~0); glStencilClear(0xA); glClear(GL_STENCIL_BUFFER_BIT); glDepthMask(0); glColorMask(0,0,0,0); glDisable(GL_CULL_FACE); glEnable(GL_STENCIL_TEST); glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT); glActiveStencilFaceEXT(GL_BACK); glStencilOp(GL_KEEP, // stencil test fail GL_ZERO, // depth test fail GL_REPLACE); // depth test pass glStencilMask(0xC); glStencilFunc(GL_ALWAYS, 0x4, ~0); glActiveStencilFaceEXT(GL_FRONT); glStencilOp(GL_KEEP, // stencil test fail GL_ZERO, // depth test fail GL_REPLACE); // depth test pass glStencilMask(0x3); glStencilFunc(GL_ALWAYS, 0x1, ~0); renderConvexPolyhedra();
[/QUOTE]
Here are my calculations:
Front Faces
Mask 1100 (0xC)
Ref 0100 (0x4)
RESULTS
Stencil Value 1010 (0xA)
Depth Fail 0010 (0x2)
Depth Pass 0110 (0x6)
Back Faces
Mask 0011 (0x3)
Ref 0001 (0x1)
RESULTS
Stencil Value 0010
Depth Fail 0000 (0x0)
Depth Pass 0001 (0x1)
Stencil Value 0110
Depth Fail 0100 (0x4)
Depth Pass 0101 (0x5)
Did I make a stupid mistake somewhere?