El Thursday 15 November 2007 12:28:43 Joakim Simonsson escribió:
> Hi,
>
> I want to generate a grid. I have done this with triangle strips, but I
> want to try to do it with the triangle primitive instead.
>
> Is it possible to define vertices in one array, and vertex-indices in
> another array that forms the triangles, for example:
>
> The indices:
>
> 00 01 02 03
> 04 05 06 07
> 08 09 10 11
> 12 13 14 15
>
> The index array: { 00, 04, 01, 01, 04, 05, ..., 11, 14, 15 }
>
> In the osgGeometry example this approach is not used. Is it because it is
> not supported by OpenGL or OpenSceneGraph?
I think it is. From the very same example (osggeometry):
osg::Vec2 myTexCoords[] =
{
osg::Vec2(0,1),
osg::Vec2(0,0),
osg::Vec2(1,0),
osg::Vec2(1,1)
};
int numTexCoords = sizeof(myTexCoords)/sizeof(osg::Vec2);
// pass the created tex coord array to the points geometry object,
// and use it to set texture unit 0.
polyGeom->setTexCoordArray(0,new
osg::Vec2Array(numTexCoords,myTexCoords));
// well use indices and DrawElements to define the primitive this time.
unsigned short myIndices[] =
{
0,
1,
2,
3
};
int numIndices = sizeof(myIndices)/sizeof(unsigned short);
// Theere are three variants of the DrawElements osg::Primitive,
UByteDrawElements which
// contains unsigned char indicies, UShortDrawElements which contains
unsigned short indices,
// and UIntDrawElements whcih contains ... unsigned int indices.
// The first parameter to DrawElements is
polyGeom->addPrimitiveSet(new
osg::DrawElementsUShort(osg::PrimitiveSet::QUADS,numIndices,myIndices));
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org