Re: [osg-users] Problem with clearing the stencil buffer

2015-03-27 Thread Şan Güneş
This issue is solved. To anyone who is wondering, it was because the quad
one was rendered before the quad two(duh). This means the stencil test of
quad one was made before quad two managed to set the stencil buffer.

The solution was to set the quad two to be rendered before anything else in
the scene

> ss_two->setRenderBinDetails(-1, "RenderBin");
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Problem with clearing the stencil buffer

2015-03-19 Thread Şan Güneş
Hello everyone, I'm trying to use stencils and I'm not sure what I'm
missing. Basically I have two quads in my scene. I want the quad two to set
the stencil buffer to 1, and I want the quad one to be visible only where
the stencil buffer is not 1.

So far I am getting the result which I want if I don't clear the stencil
buffer. Of course in that case when I rotate the scene using the viewer,
the stencil buffer gets painted to 1's(because of the quad two) and I don't
see the quad one even on places where quad two is not positioned anymore.

However when I clean the stencil buffer(see below), I don't get the result
that I want.

> viewer->getCamera()->setClearMask(GL_COLOR_BUFFER_BIT |
> GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

In this case both of the quads are visible. I'm suspecting that the stencil
buffer gets cleared before the stencil check is done.

Here is a part of my code where I set the stencils.

> osg::ref_ptr transform_one = new
> osg::PositionAttitudeTransform();
> osg::ref_ptr transform_two = new
> osg::PositionAttitudeTransform();
> transform_one->addChild(createQuad());
> transform_two->addChild(createQuad());
> transform_two->setScale(osg::Vec3(0.5, 0.5, 0.5));
> transform_two->setPosition(osg::Vec3(0.25, 0.2, 0.25));
>
> // --- Begin stencil related stuff
> osg::ref_ptr ss_one = transform_one->getOrCreateStateSet();
> osg::ref_ptr ss_two = transform_two->getOrCreateStateSet();
> osg::ref_ptr stencil_one = new osg::Stencil();
> osg::ref_ptr stencil_two = new osg::Stencil();
> stencil_two->setFunction(osg::Stencil::ALWAYS, 1, ~0u);
> stencil_two->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP,
> osg::Stencil::REPLACE);
> stencil_one->setFunction(osg::Stencil::NOTEQUAL, 1, ~0u);
> stencil_one->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP,
> osg::Stencil::KEEP);
> ss_one->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
> ss_two->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
> osg::ref_ptr cm_one = new osg::ColorMask();
>
// I play with the parameters below to see the position of the quad two

cm_one->setMask(false, false, false, false);
> ss_two->setAttribute(cm_one);
> ss_two->setAttributeAndModes(stencil_two, osg::StateAttribute::ON |
> osg::StateAttribute::OVERRIDE);
> ss_one->setAttributeAndModes(stencil_one, osg::StateAttribute::ON |
> osg::StateAttribute::OVERRIDE);


Any help would be appreciated, I am sure I'm missing something really basic
:)
Thanks
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Problem with clearing the stencil buffer

2015-03-19 Thread Şan Güneş
Hello everyone, I'm trying to use stencils and I'm not sure what I'm
missing. Basically I have two quads in my scene. I want the quad two to set
the stencil buffer to 1, and I want the quad one to be visible only where
the stencil buffer is not 1.

So far I am getting the result which I want if I don't clear the stencil
buffer. Of course in that case when I rotate the scene using the viewer,
the stencil buffer gets painted to 1's(because of the quad two) and I don't
see the quad one even on places where quad two is not positioned anymore.

However when I clean the stencil buffer(see below), I don't get the result
that I want.

> viewer->getCamera()->setClearMask(GL_COLOR_BUFFER_BIT |
> GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

In this case both of the quads are visible. I'm suspecting that the stencil
buffer gets cleared before the stencil check is done.

Here is a part of my code where I set the stencils.

> osg::ref_ptr transform_one = new
> osg::PositionAttitudeTransform();
> osg::ref_ptr transform_two = new
> osg::PositionAttitudeTransform();
> transform_one->addChild(createQuad());
> transform_two->addChild(createQuad());
> transform_two->setScale(osg::Vec3(0.5, 0.5, 0.5));
> transform_two->setPosition(osg::Vec3(0.25, 0.2, 0.25));
>
> // --- Begin stencil related stuff
> osg::ref_ptr ss_one = transform_one->getOrCreateStateSet();
> osg::ref_ptr ss_two = transform_two->getOrCreateStateSet();
> osg::ref_ptr stencil_one = new osg::Stencil();
> osg::ref_ptr stencil_two = new osg::Stencil();
> stencil_two->setFunction(osg::Stencil::ALWAYS, 1, ~0u);
> stencil_two->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP,
> osg::Stencil::REPLACE);
> stencil_one->setFunction(osg::Stencil::NOTEQUAL, 1, ~0u);
> stencil_one->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP,
> osg::Stencil::KEEP);
> ss_one->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
> ss_two->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
> osg::ref_ptr cm_one = new osg::ColorMask();
>
// I play with the parameters below to see the position of the quad two

cm_one->setMask(false, false, false, false);
> ss_two->setAttribute(cm_one);
> ss_two->setAttributeAndModes(stencil_two, osg::StateAttribute::ON |
> osg::StateAttribute::OVERRIDE);
> ss_one->setAttributeAndModes(stencil_one, osg::StateAttribute::ON |
> osg::StateAttribute::OVERRIDE);


Any help would be appreciated, I am sure I'm missing something really basic
:)
Thanks
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org