Stencil visiblity test

Started by
2 comments, last by Kalidor 18 years, 7 months ago
is it possible to use the stencil buffer to determine if a vertex is in a specified region? my idea: - render a cube or what which should be the visible region to stencil - bool render_object = wouldVertexPassTheStencilTest(glVertex()) and then render if render_object was true. so i would have a visiblity test with only one glVertexCall (a point) hope you understand me ..... thanks eitsch
Advertisement
Stencil buffer (actually, like all other buffers) operates on pixels - not vertices. Anyway, you can use it for determining particular fragments of the screen where 'rendering is allowed' (it can be your 'visible region'). For example, you can render a shape of your cockpit HUD to the stencil buffer and then draw the outside world without worrying that some parts of the HUD will become covered by other objects. Maybe it wasn't the best example but I hope that you get the idea. ;) Probably more intuitive usage of stencil buffer it is specyfing screen regions for reflections and shadows.

Putting it simply, here are OpenGL commands related to the stencil test :

glEnable(GL_STENCIL_TEST); // must be enabled in order to perform the stencil test

glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF); // specifies the stencil function (in this case the test always passes and writes '1' to the stencil buffer - useful when drawing regions to the buffer)

glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // says what to do when 1) stencil test fails 2) depth test fails 3) both stencil and depth test succeded

For more information I suggest googling or looking into The Red Book.

Hope it helps!
___Quote:Know where basis goes, know where rest goes.
i understand. thanks

so my idea is not realizable...
Another thing is that it's usually a bad idea to read something from the video card because it stalls the pipeline. If the region you want to test a vertex against is in screen space, a better way would be to use gluProject to get the screen space coordinates of the vertex and just check if that's within the region.

This topic is closed to new replies.

Advertisement