glVertexPointer / glTexCoordPointer indexing issue

Hello all,

I’ve been running into a problem I don’t know how to sort out. Here’s the point:

I have arrays containing vertices, normals and texcoords. The problem is that these arrays are not indexed the same way :s

I mean: vertices are indexed as absolute index with respect to the current object, the object contains an array with polygons, each containing the indices of the vertices used to build the polygon. In every polygon there is also an array with UV coordinates, but indexed the same way the INDICES to vertices are indexed, not vertices temselves! Here’s the code

glVertexPointer(3, GL_FLOAT, sizeof(dmf_vector3_t), &(objPtr->vertices[0]));
glTexCoordPointer(2, GL_FLOAT, sizeof(dmf_vector2_t), &(polyPtr->texcoords[0].vertices[0]));

glDrawElements(GL_TRIANGLES, polyPtr->numVertices, GL_UNSIGNED_INT, &(polyPtr->indices[0]) );

objPtr->vertices points to the vertices
polyPtr->indices contains the indices of the vertices needed
polyPtr->texcoords[0].vertices contains UV coordinates… BUT polyPtr->texcoords[0].vertices[0], for instance, refers to the vertex designated by polyPtr->indices[0], NOT to objPtr->vertices[0]…

Could someone provide enlightment about this matter? Thanks alot!


If attributes are indexed in different ways, you cannot use the vertex array interface to draw them. You must have one and only one index array, and that index array must index all enabled arrays.

This is a FAQ; I’ve written an answer here .