Advertisement

StencilFunc ?

Started by January 18, 2004 09:01 AM
5 comments, last by Tree Penguin 21 years, 1 month ago
Hi, what''s the meaning of the ''ref'' argument in the glStencilFunc function, i know the first argument is the stencil test function which uses the 3rd argument (mask) for testing. Thanks in advance!
The ref parameter is the reference value for the test function. For example, if the test function is < (GL_LESS), then the stencil test passes if ref<stencil. stencil is the value in the stencil buffer being tested, and both ref and stencil are masked by mask before the test.
Advertisement
Could you give an examples on that and describe exactly what the arguments are being used for (i failed to really understand your explanation as it is something completely different from what i thought).

Thanks in advance !
Let''s say you have three pixels in the frame buffer whose stencil value is 1, 2 and 3, respectively. Then you set the stencil function to GL_EQUAL, and the reference to 2, i.e. glStencilFunc(GL_EQUAL, 2, ...). The first pixel will have a value of 1, which is not equal to 2 (the reference), and the stencil test till fail. The second pixel have a stencil value of 2, and 2==2, so the stencil test passes. The test for the third pixel will fail, because 3!=2.

Now let''s say the stencil function is GL_LESS instead, i.e. glStencilFunc(GL_LESS, 2, ...). The first pixel have a value of 1, but since the reference is not less than 1, the test will fail. The second pixel have a stencil value of 2, and since the 2 is not less than 2, the test will, again, fail. The third test will pass, because the reference is less than the stencil value in the third pixel.
Thanks, now what''s the 3rd argument used for ?
mask(the third argument) is bitwise ANDed with both the existing stencil value and the reference value before the test takes place. It's probably best to put it as 0xffffffff

[edited by - Monder on January 18, 2004 2:03:53 PM]
Advertisement
Thanks! I think i understand it, now i can implement it in my creative contest entry .

This topic is closed to new replies.

Advertisement