[osg-users] Color array always red
Carlos Meira
cesmsp at gmail.com
Tue Jan 12 14:12:47 PST 2016
Hi,
Im trying create a simple white quad but it is always red.
I took the example osgGeometry like this...
osg::Geode* geode = new osg::Geode();
// create Geometry object to store all the vertices and lines primitive.
osg::Geometry* polyGeom = new osg::Geometry();
osg::ref_ptr<osg::Vec4Array> shared_colors = new osg::Vec4Array;
shared_colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
osg::ref_ptr<osg::Vec3Array> shared_normals = new osg::Vec3Array;
shared_normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
float width = 1000.0f;
float height = 1000.0f;
// note, anticlockwise ordering.
osg::Vec3 myCoords[] =
{
osg::Vec3((width/2)*(-1),(height/2)*(-1), 0.0f),
osg::Vec3(width/2, (height/2)*(-1), 0.0f),
osg::Vec3(width/2, height/2 , 0.0f),
osg::Vec3((width/2)*(-1), height/2, 0.0f),
osg::Vec3(0.238942, 0.0f, -0.251302),
osg::Vec3(0.333696, 0.0f, 0.0329576),
osg::Vec3(0.164788, 0.0f, -0.0453167),
osg::Vec3(0.13595, 0.0f, -0.255421)
};
int numCoords = sizeof(myCoords)/sizeof(osg::Vec3);
osg::Vec3Array* vertices = new osg::Vec3Array(numCoords,myCoords);
// pass the created vertex array to the points geometry object.
polyGeom->setVertexArray(vertices);
// use the shared color array.
polyGeom->setColorArray(shared_colors.get(), osg::Array::BIND_OVERALL);
// use the shared normal array.
polyGeom->setNormalArray(shared_normals.get(), osg::Array::BIND_OFF);
// This time we simply use primitive, and hardwire the number of coords to use
// since we know up front,
polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,numCoords));
// printTriangles("Quads",*polyGeom);
// add the points geometry to the geode.
geode->addDrawable(polyGeom);
What I m doing wrong ??
...
Thank you!
Cheers,
Carlos
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=65985#65985
More information about the osg-users
mailing list