[osg-users] Transparency problem
Yu Jie
beingbad at 163.com
Thu Jun 13 02:29:05 PDT 2019
Hi, Everyone! Is there anybody can help to solve this problem. I tried to make geode node to be transparency in my application. A piece of my code is list below:
osg::StateSet* stateSet = geode->getOrCreateStateSet();
stateSet->setMode(GL_BLEND, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
osg::BlendFunc* blendFunc = dynamic_cast<osg::BlendFunc*>(stateSet->getAttribute(osg::StateAttribute::BLENDFUNC));
if (nullptr == blendFunc) {
blendFunc = new osg::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
stateSet->setAttribute(blendFunc, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
} else {
blendFunc->setSource(GL_SRC_ALPHA);
blendFunc->setDestination(GL_ONE_MINUS_SRC_ALPHA);
}
osg::Material* mat = dynamic_cast<osg::Material*>(stateSet->getAttribute(osg::StateAttribute::MATERIAL));
if (nullptr == mat) {
mat = new osg::Material;
stateSet->setAttribute(mat,osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
}
mat->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4(0.2f,0.2f,0.2f,0.3f));
mat->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4(0.8f,0.8f,0.8f,0.3f));
mat->setTransparency(osg::Material::FRONT_AND_BACK, 0.4);
osg::LightModel* lm = dynamic_cast<osg::LightModel *>(stateSet->getAttribute(osg::StateAttribute::LIGHTMODEL));
if (nullptr == lm) {
lm = new osg::LightModel();
stateSet->setAttribute(lm,osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
}
lm->setTwoSided(false);
stateSet->setAttribute(lm, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
it seems like something is wrong as the transparency effect is miss-up. could anybody figure out what i missed and how to solve this problem.
thanks very much for your help!
Cheers,
Yu
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=76283#76283
Attachments:
http://forum.openscenegraph.org//files/transparency_missup_209.png
More information about the osg-users
mailing list