virtualchetan
09-17-2003, 12:28 PM
Dear All,
I hope this post is advanced enough to appear here! :-)
I am trying to do child clipping using stencil buffer,
i.e. if object Obj1 (e.g. a push button) is child of object O2
( e.g. a dialog box), the part of O1 outside Obj2 should be not be drawn.
----------------
What I did successfully is:
//init stencil
glEnable(GL_STENCIL_TEST);
glClearStencil(0x0);
glClear(GL_STENCIL_BUFFER_BIT);
//set up stencil for Obj1
glStencilFunc (GL_ALWAYS, 0x1, 0x1);
glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE);
draw_Obj1_the_container();
//set up stencil for Obj2 - child clipping
glStencilFunc (GL_EQUAL, 0x1, 0x1);
glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
draw_Obj2_the_child();
//turn off the stencil
glDisable(GL_STENCIL_TEST);
------------------
What I understand is:
- Stencil buff is filled with '0'
- When Obj1 is drawn in the color buffer, corresponding slots
in Stencil are filled with '1'
- While drawing Obj2, for each pixel, the color buffer is filled
with Obj2 color only if the corresponding slots in Stencil buf
contain '1' (i.e. inside Obj2)
Is this correct?
-----------------
1)Whats the relation between color buffer and stencil buffer,
R they filled at the same time? with what values?
2) Whats the use of 'mask' argument for glStencilFunc(....)
3) why glStencilOp(..) has arguments related to the Depth Buffer?
4)If stencil buffer is Draw/ Dont Draw why it needs multiple bits (mine has 8)
5)How do I implement 'nested' stencils, using one bitplane of the stencil
buffer at a time?
In that case, I can have upto 8 levels(mine has 8 bitplanes)
I am doing hierarchical rendering, so Obj2( or any child) doesnt know
about Obj1 (its parent), In this case how a child will know which bitplane
of the stencil buffer is not used by its parent, so that it can use that plane.
------------------
- Chetan
I hope this post is advanced enough to appear here! :-)
I am trying to do child clipping using stencil buffer,
i.e. if object Obj1 (e.g. a push button) is child of object O2
( e.g. a dialog box), the part of O1 outside Obj2 should be not be drawn.
----------------
What I did successfully is:
//init stencil
glEnable(GL_STENCIL_TEST);
glClearStencil(0x0);
glClear(GL_STENCIL_BUFFER_BIT);
//set up stencil for Obj1
glStencilFunc (GL_ALWAYS, 0x1, 0x1);
glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE);
draw_Obj1_the_container();
//set up stencil for Obj2 - child clipping
glStencilFunc (GL_EQUAL, 0x1, 0x1);
glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
draw_Obj2_the_child();
//turn off the stencil
glDisable(GL_STENCIL_TEST);
------------------
What I understand is:
- Stencil buff is filled with '0'
- When Obj1 is drawn in the color buffer, corresponding slots
in Stencil are filled with '1'
- While drawing Obj2, for each pixel, the color buffer is filled
with Obj2 color only if the corresponding slots in Stencil buf
contain '1' (i.e. inside Obj2)
Is this correct?
-----------------
1)Whats the relation between color buffer and stencil buffer,
R they filled at the same time? with what values?
2) Whats the use of 'mask' argument for glStencilFunc(....)
3) why glStencilOp(..) has arguments related to the Depth Buffer?
4)If stencil buffer is Draw/ Dont Draw why it needs multiple bits (mine has 8)
5)How do I implement 'nested' stencils, using one bitplane of the stencil
buffer at a time?
In that case, I can have upto 8 levels(mine has 8 bitplanes)
I am doing hierarchical rendering, so Obj2( or any child) doesnt know
about Obj1 (its parent), In this case how a child will know which bitplane
of the stencil buffer is not used by its parent, so that it can use that plane.
------------------
- Chetan