[osg-users] Get all vertices of an OSG Group

David Knipp David.Knipp at gmx.net
Thu Mar 31 13:31:26 PDT 2016

Hi Bemt,

i think you got something wrong in the beginning. There are 3 possible ways to apply a color to a vertex:

- Material: 
  Materials define how the surface is interacting with lights. 
  Most times you are only intereseted in diffuse value.

osg::Material * mat = dynamic_cast<osg::Material*>(geometry)->getOrCreateStateSet()->getAttribute(osg::StateAttribute::MATERIAL));

- ColorArray:
  A simple color value that is just applied to a vertex


- Texture:
  An image applied on the surface:

osg::Texture2D * texture = dynamic_cast<osg::Texture2D*>(geometry)->getOrCreateStateSet()->getTextureAttribute(0, osg::StateAttribute::TEXTURE));

All these are DIFFERENT ways to apply a color to a vertex. You should have said in the beginning that you apply a texture to all vertices. : )

Your answer should be for one position:

i : index of current vertex

osg::Vec2Array * texCoords = dynamic_cast<osg::Vec2Array *>(geometry->getTexCoordArray(0)); 
osg::Vec4 color = texture->getImage()->getColor(texCoords->operator[](i));


Read this topic online here:

More information about the osg-users mailing list