Hi,
I am trying to use the stencil buffer to implement CSG Boolean operations.

As part of this I need to selectively render the front and back faces of the 
two objects in order to test depth and update the stencil buffer

What I would like to know is how can I enable face culling in OSG ? 
(I understand from the quick start guide that attaching an attribute to a 
stateset is only a desired state and doesn’t issue an OpenGL command, so it may 
not do it, the code stub below doesn’t seem to have any affect and the whole 
cylinder is rendered) 

osg::StateSet* state = myCylinderGeode->getOrCreateStateSet();
osg::CullFace* cf = new osg::CullFace(osg::CullFace::FRONT);
state->setAttribute( cf );
 
The second question is how can I selectively render the first object (object a) 
modify the stencil and face culling then render the second object (object b)? 

Should I use a node mask on the cull traversal as mentioned in the node mask 
tutorial? (if so any pointers on how to do it would be great)

If anyone could help or point me in the right direction it would be greatly 
appreciated.  

The OpenGL code implementation is below.

The openGL  function is
firstInsideSecond(void (*a) (void), void (*b) (void), GLenum face, GLenum test)
{
  glEnable(GL_DEPTH_TEST);
  glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
  glCullFace(face);     /* controls which face of a to use */
  a();                  /* draw a face of a into depth buffer */

  /* use stencil plane to find parts of a in b */
  glDepthMask(GL_FALSE);
  glEnable(GL_STENCIL_TEST);
  glStencilFunc(GL_ALWAYS, 0, 0);
  glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
  glCullFace(GL_BACK);
  b();                  /* increment the stencil where the front face of b is 
                           drawn */
  glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
  glCullFace(GL_FRONT);
  b();                  /* decrement the stencil buffer where the back face
                           of b is drawn */
  glDepthMask(GL_TRUE);
  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

  glStencilFunc(test, 0, 1);
  glDisable(GL_DEPTH_TEST);

  glCullFace(face);
  a();                  /* draw the part of a that's in b */
}part of a that's in b */
The function call is
firstInsideSecond(a, b, GL_BACK, GL_NOTEQUAL);
with a and b being a box and a cylinder.


Thank you!

Cheers,
Craig

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=41383#41383





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to