Hello, My OSG app is drawing a collection of quads most of which are contained
in a single vertex array in a single drawable in a single geometry and geode.
There is then a background quad in a seperate drawable, geometry and geode. In
the code below when I comment out the line that adds the background quad's
drawable to its geometry the color for the collection of quads (in a seperate
drawable, geometry and geode) is fine. However, when this line is included the
color for all the other quads gets messed up (washed out and semi-transparent).
I'm sure there is some color/material state aspect that I either don't
understand or overlooked, but I just can't find it. Here is the code that
creates the drawables and adds them to their respective geometries and geodes
and below that is the code that is used to dynamicly add the vertices for the
collection of quads (not the background quad). Thanks for any help.
{//Create background
// background vertices
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array(4);
(*coords)[0] = osg::Vec3f( -gridSize_d/2, -gridSize_d/2, 1.0);
(*coords)[1] = osg::Vec3f( gridSize_d/2, -gridSize_d/2, 1.0);
(*coords)[2] = osg::Vec3f( gridSize_d/2, gridSize_d/2, 1.0);
(*coords)[3] = osg::Vec3f( -gridSize_d/2, gridSize_d/2, 1.0);
geom->setVertexArray(coords.get());
// background color
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
// background normals
osg::ref_ptr<osg::Vec3Array> norms = new osg::Vec3Array(1);
(*norms)[0] = osg::Vec3d(0,0,1);
geom->setNormalArray(norms.get());
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));
// background texture
osg::ref_ptr<osg::StateSet> stateset;
osg::ref_ptr<osg::Texture2D> texture;
if (backgroundImage.get())
{
stateset = new osg::StateSet;
texture = new osg::Texture2D;
texture->setImage(backgroundImage.get());
stateset->setTextureAttributeAndModes(0,texture.get(),osg::StateAttribute::ON);
osg::BlendFunc *blendFunc = new osg::BlendFunc;
blendFunc->setFunction(GL_SRC_ALPHA, GL_ONE);
stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
stateset->setAttributeAndModes(new osg::BlendFunc, osg::StateAttribute::ON );
stateset->setAttributeAndModes( blendFunc, osg::StateAttribute::ON );
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
}
osg::ref_ptr<osg::Vec2Array> tcoords = new osg::Vec2Array(4);
(*tcoords)[0].set(0.0f,0.0f);
(*tcoords)[1].set(1.0f,0.0f);
(*tcoords)[2].set(1.0f,1.0f);
(*tcoords)[3].set(0.0f,1.0f);
geom->setTexCoordArray(0,tcoords.get());
geom->setStateSet(stateset.get());
// background Xforms
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
geode->addDrawable(geom.get());
modelXForm->addChild(geode.get());
}//Create background
{//Create nodes
// create Geometry object to store all the vetices and lines primtive.
nodeGeode = new osg::Geode();
modelXForm->addChild(nodeGeode.get());
osg::Geometry* polyGeom = new osg::Geometry();
osg::Vec3Array* vertices = new osg::Vec3Array();
polyGeom->setVertexArray(vertices);
// color
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
polyGeom->setColorArray(colors);
polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
//texture
osg::ref_ptr<osg::StateSet> stateset;
osg::ref_ptr<osg::Texture2D> texture;
if (nodeImage.get())
{
stateset = new osg::StateSet;
texture = new osg::Texture2D;
texture->setImage(nodeImage.get());
stateset->setTextureAttributeAndModes(0,texture.get(),osg::StateAttribute::ON);
osg::BlendFunc *blendFunc = new osg::BlendFunc;
blendFunc->setFunction(GL_SRC_ALPHA, GL_ONE);
stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
stateset->setAttributeAndModes(new osg::BlendFunc, osg::StateAttribute::ON );
stateset->setAttributeAndModes( blendFunc, osg::StateAttribute::ON );
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
}
nodeTcoords = new osg::Vec2Array();
polyGeom->setStateSet(stateset.get());
//normals
osg::Vec3Array* normals = new osg::Vec3Array;
normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));
polyGeom->setNormalArray(normals);
polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
//add to nodeGeode
nodeGeode->addDrawable(polyGeom);
}//Create nodes
_________________________________________________________________
Climb to the top of the charts! Play Star Shuffle: the word scramble
challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_oct_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org