Hello Please, I would like to show you some lines of the code I use for a project. In one scene, I can ask some geodes to: - change their color emission (the objective is to seem them with a kind of red colour) - change their opacity (with a value from 0 to 1 : 0 is fully invisible geode, 1 is fully opaque)
1) In the creation of the scene, I do this: osg::ref_ptr<osg::StateSet> stateSet; for (all geodes in the scene) { stateSet = new osg::StateSet(); osg::Material* material = dynamic_cast< osg::Material* >( stateSet->getAttribute(osg::StateAttribute::MATERIAL)); if (material == NULL) stateSet->setAttributeAndModes( new osg::Material ) ; geode->getStateSet()->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE); geode->getStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); geode->getStateSet()->setBinName("transparent"); geode->getStateSet()->setBinNumber(0); } stateSet = NULL; 2) When I want to change the color emission of a geode, I do this: osg::Material *material; for (all geodes in the scene) { material = (osg::Material *) geode->getStateSet()->getAttribute(osg::StateAttribute::MATERIAL); if (ChangeColour) { material->setColorMode(osg::Material::EMISSION); material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f)); geode->getOrCreateStateSet()->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE); } else { material->setColorMode(osg::Material::OFF); material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0.f, 0.f, 0.0f, 1.0f)); geode->getOrCreateStateSet(g)->setAttributeAndModes(material, osg::StateAttribute::OFF); } } material = NULL; 3) When I want to change the opacity/transparency level of the geode, I do this: ApplyOpacity (float Opacity, Geode geode) { osg::Material * material = (osg::Material *) geode->getStateSet()->getAttribute(osg::StateAttribute::MATERIAL); if (Opacity != 1.) { material->setTransparency(osg::Material::FRONT_AND_BACK, 1. - Opacity); geode->getStateSet()->setRenderBinDetails(0, "transparent"); geode->getStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON ); geode->getStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); geode->getStateSet()->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE); } else { geode->getStateSet()->setMode( GL_BLEND, osg::StateAttribute::OFF ); geode->getStateSet()->setAttributeAndModes(material, osg::StateAttribute::OFF); } } ... It mainly works, it's even compatible : I can both apply a red colour and a transparency to a same geode. However: - if I set an opacity of 0.5 to one geode... if after I put a red colour... it is OK... but if after I come back to opacity=1, the red colour disappears - same way, if i put 0.5 opacity and red colour and if I remove the red colour, the transparency disappears. The problem probably comes from the setAttributeAndModes(..., OFF) but if I don't use those lines, I lose the visual aspect of the geode. I really don't know how make those 2 effects comaptible... If you have an idea ? Thank you very much! ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=34814#34814 _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org