PDA

View Full Version : glDrawElements ??



garcij01
10-09-2000, 12:47 PM
I've been playing with glDrawElements() I can specify an array of triangles/polygons to draw. It works just fine, but there's no way to specify triangles as vertex index to be draw.
e.g if I have an array of vertex [...] and my triangle vertex index is [0,1,2,6,7,8] how can I draw these two triangles using open gl?.

I can do the rendering myself making calls to glVertex3f but I feel there's a big overhead doing it this way.

If there was a way I can pass the vertex index to open gl as an array it would be very useful.

Thanx!

DrakanFyr
10-09-2000, 05:58 PM
This is the way I do it and it seems to work pretty well:

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, Vertices);

glDrawElements(GL_TRIANGLES, numTriangles, GL_UNSIGNED_SHORT, Triangles);

where Vertices is an array of GL_FLOAT's with Vertices[0] being the first vertex's x value, Vertices[1] being the first vertex's y value, Vertices[2] being the first vertex's z value, Vertices[3] being the second vertex's x value, and so on. I assume you already do something very similar to this.

Triangles is and array of int's where the first 3 values are indexes to the first triangle's vertices and so on.

glDrawElements() takes the Triangles array and uses it to pull refrenced vertices from the Vertices array specified by glVertexPointer().

Rendering this way will give you a pretty significant speed boost.

I hope this answers your question. There is a good example in the OpenGL SuperBible 2nd edition.

garcij01
10-11-2000, 03:23 PM
Originally posted by garcij01:
I've been playing with glDrawElements() I can specify an array of triangles/polygons to draw. It works just fine, but there's no way to specify triangles as vertex index to be draw.
e.g if I have an array of vertex [...] and my triangle vertex index is [0,1,2,6,7,8] how can I draw these two triangles using open gl?.

I can do the rendering myself making calls to glVertex3f but I feel there's a big overhead doing it this way.

If there was a way I can pass the vertex index to open gl as an array it would be very useful.

Thanx!

Thanks that's exactly what I'm doing for the triangles.

I know I can pass an array of normals the same way I pass an array of vertex.

Is there any way of passing an rray of normal indexes?

DFrey
10-11-2000, 03:38 PM
Nope. When using glDrawElements, the indices passed index into all active arrays, vertex, normal, texture coordinate, color, etc.