You do not show how you set the color and material on the triangles If this is not specified then you will pickup what ever the last color and/or material that was used by Opengl
Gordon Product Manager 3d __________________________________________________________ Gordon Tomlinson Email : gtomlinson @ overwatch.textron.com __________________________________________________________ -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Konkle, Daniel T AMRDEC/Dynetics Sent: Thursday, March 12, 2009 12:04 PM To: OpenSceneGraph Users Subject: [osg-users] second newbie question reiterated with drawLine(UNCLASSIFIED) Classification: UNCLASSIFIED Caveats: NONE Any insight would be welcome. So I'm drawing several triangles on my scene. here is the code that draws the first 2. I'm reusing the first same geode. The strange thing is that the 'right triangle' is a different color (black) than the 'left triangle' (light green) I'm actually drawing 2 others and they are black too. I need them to be green. Can anyone tell me what I'm doing wrong? It makes no sense to me. Danny osg::Vec3Array* tri = new osg::Vec3Array; tri->push_back(osg::Vec3(0.0f, -0.1f, depth)); tri->push_back(osg::Vec3(0.1f, 0.0f, depth)); tri->push_back(osg::Vec3(0.0f, 0.1f, depth)); osg::ref_ptr<osg::Geode> triangle = new osg::Geode(); triangle->addDrawable( drawLines( tri, 0 ) ); // right triangle { osg::ref_ptr<osg::MatrixTransform> translate = new osg::MatrixTransform; osg::Matrix tran_mat = osg::Matrix::translate( hud_aspect,0.0f, 0.0f ); translate->setMatrix( tran_mat ); osg::ref_ptr<osg::MatrixTransform> rotate = new osg::MatrixTransform; osg::Matrix rot_mat = osg::Matrix::rotate( M_PI, 0.0f, 0.0f, 1.0f); rotate->setMatrix( rot_mat ); camera->addChild(translate.get()); translate->addChild( rotate.get() ); rotate->addChild( triangle.get() );; } // left triangle { osg::Matrix m; osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform; m.makeTranslate( -hud_aspect, 0.0f, 0.0f ); mt->setMatrix( m ); camera->addChild(mt.get()); mt->addChild( triangle.get() );. } // create LINES osg::Geometry * drawLines( osg::Vec3Array * vertices, int colorIndex ) { // create Geometry object to store all the vertices and lines primitive. osg::Geometry* linesGeom = new osg::Geometry(); // pass the created vertex array to the points geometry object. linesGeom->setVertexArray(vertices); // set the colors as before, plus using the above osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4( colorVec[colorIndex][0], colorVec[colorIndex][1], colorVec[colorIndex][2], colorVec[colorIndex][3])); linesGeom->setColorArray(colors); linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); // set the normal in the same way color. osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); linesGeom->setNormalArray(normals); linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); // This time we simply use primitive, and hardwire the number of coords to use // since we know up front, //linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,vertices->size())); linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,vertices->size())); osg::StateSet* stateset = linesGeom->getOrCreateStateSet(); stateset->setMode(GL_BLEND,osg::StateAttribute::ON); stateset->setAttribute(new osg::PolygonOffset(1.0f,1.0f),osg::StateAttribute::ON); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); stateset->setRenderBinDetails(11, "RenderBin"); // add the points geometry to the geode. return linesGeom; } Classification: UNCLASSIFIED Caveats: NONE _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or g _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

