Hi,
I'ld like to have the triangles in the code below drawn colored on both sides.
As the normals are pointing towards the triangles one side gets painted black,
even though osg::Material::FRONT_AND_BACK is specified.
Do you have an idea how I can achieve this?
Thank you!
Cheers,
Matthias
// Forum problem. Add < in the include lines.
#include osg/Geode>
#include osg/Geometry>
#include osg/Material>
#include osg/Vec3>
#include osgViewer/Viewer>
osg::Node* createScene()
{
osg::Geode* geode = new osg::Geode();
osg::ref_ptr<osg::Vec3Array> shared_normals = new osg::Vec3Array;
shared_normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
{
osg::Geometry* polyGeom = new osg::Geometry();
osg::Vec3 myCoords[] =
{
// note in anticlockwise order.
osg::Vec3(-1.12056, -2.15188e-09, -0.840418),
osg::Vec3(-0.95165, -2.15188e-09, -0.840418),
osg::Vec3(-1.11644, 9.18133e-09, -0.716827),
// note in anticlockwise order.
osg::Vec3(-0.840418, 9.18133e-09, -0.778623),
osg::Vec3(-0.622074, 9.18133e-09, -0.613835),
osg::Vec3(-1.067, 9.18133e-09, -0.609715),
};
int numCoords = sizeof(myCoords)/sizeof(osg::Vec3);
osg::Vec3Array* vertices = new osg::Vec3Array(numCoords,myCoords);
polyGeom->setVertexArray(vertices);
polyGeom->setNormalArray(shared_normals.get());
polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
polyGeom->addPrimitiveSet(new
osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,6));
osg::StateSet* stateSet = new osg::StateSet();
osg::Material* material = new osg::Material;
material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
material->setAmbient(osg::Material::FRONT_AND_BACK,
osg::Vec4(1.0, 0.0, 0.0, 1));
material->setDiffuse(osg::Material::FRONT_AND_BACK,
osg::Vec4(1.0, 0.0, 0.0, 1));
stateSet->setAttribute(material,
osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
stateSet->setMode(GL_LIGHTING,
osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
stateSet->setMode(GL_CULL_FACE,
osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
polyGeom->setStateSet(stateSet);
geode->addDrawable(polyGeom);
}
return geode;
}
int main(int, char **)
{
osg::Group* root = new osg::Group;
root->addChild( createScene() );
osgViewer::Viewer viewer;
viewer.setSceneData( root );
return viewer.run();
}
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=51182#51182
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org