In the osgWorks osgwTools library, TransparencyUtils.cpp, I enable
transparency by first copying the original StateSet and saving it as
UserData, then modifying the active StateSet to turn on transparency
(BlendFunc, RenderBin, etc).

To disable transparency, I simply restore the original StateSet from
UserData.
   -Paul



On Fri, May 30, 2014 at 5:08 AM, sunpeng <[email protected]> wrote:

> I use following code to set transparency:
>
> osg::StateSet* state = root->getOrCreateStateSet();
>
>
> state->setMode(GL_LIGHTING,osg::StateAttribute::OFF|osg::StateAttribute::PROTECTED);
>
> state->setMode(GL_BLEND,osg::StateAttribute::ON);
> state->setMode(GL_DEPTH_TEST,osg::StateAttribute::ON);
> state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
>
> osg::BlendColor* bc =new osg::BlendColor(osg::Vec4(1.0,1.0,1.0,0.0));
> osg::BlendFunc*bf = new osg::BlendFunc();
> state->setAttributeAndModes(bf,osg::StateAttribute::ON);
> state->setAttributeAndModes(bc,osg::StateAttribute::ON);
> bf->setSource(osg::BlendFunc::CONSTANT_ALPHA);
> bf->setDestination(osg::BlendFunc::ONE_MINUS_CONSTANT_ALPHA);
> bc->setConstantColor(osg::Vec4(1,1,1,0.5));
>
> How to close transparency effect? I tried to use:
>  state->setMode(GL_BLEND,osg::StateAttribute::OFF);
>  state->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
>
> but it seems not work?
> tks!
>
> peng
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>


-- 
   -Paul
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to