[osg-users] wireframe darker wrt the surface color

Gianni Ambrosio g.ambrosio+osg at gmail.com
Tue Mar 21 09:00:42 PDT 2017


Hi All,
I implemented the wireframe feature as follows:


Code:
void addWireframe(osg::Group* root, osg::Node* scene)
{
   osg::ref_ptr<osg::Group> decorator = new osg::Group;
   decorator->setNodeMask(0x1);

   osg::StateSet* stateset = decorator->getOrCreateStateSet();

   osg::PolygonOffset* polyoffset = new osg::PolygonOffset;
   polyoffset->setFactor(2.0f);
   polyoffset->setUnits(2.0f);
   stateset->setAttributeAndModes(polyoffset, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);

   osg::PolygonMode* polymode = new osg::PolygonMode;
   polymode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);
   stateset->setAttributeAndModes(polymode, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);

   osg::Material* material = new osg::Material;
   material->setColorMode(osg::Material::OFF); // switch glColor usage off
   // turn all lighting off
   material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.5, 0.5f, 0.5f, 1.0f));
   material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.5, 0.5f, 0.5f, 1.0f));
   material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0, 0.0f, 0.0f, 1.0f));
   // except emission... in which we set the color we desire
   material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0.7, 0.7f, 0.7f, 1.0f));
   stateset->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
   stateset->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);

   decorator->addChild(scene);
   root->addChild(decorator);
}



Now instead of having the wireframe of a fixed color, I would like to show it in a slightly darker color wrt the color of the related geometry. Is it possible? How?

Thanks in advance,
Gianni

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








More information about the osg-users mailing list