glDrawElements() question

Hey all,

I need help! OpenGL related question.

-I want to use glDrawElements(GL_TRIANGLES … ) to render my Maya characters in OpenGL.

What i have is the following:

  • float[3] positionsArray, with nPos elements
  • float[3] normalsArray, with nNormlas elements
  • float[2] UVsArray, with nUVs elements
  • Class CVertex {WORD iPos, WORD iNormal, WORD iUV};
  • CVertex *PolysArray = {{v1, v2, v3}, {v5, v100, v89}, … }

i use:

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glVertexPointer(3, GL_FLOAT, 0, positionsArray);
glNormalPointer(GL_FLOAT, 0, normalArray);
glTexCoordPointer(2, GL_FLOAT, 0, UVsArray);

glDrawElements(GL_TRIANGLES, nPolys*3, GL_UNSIGNED_SHORT, PolysArray);

The results are that in a simple rectangle of 6 vertices works OK, but in a real model appears very rare things.

Any help will be very apreciated. Thanks.

You say the vertex array has nPos elements, and the normal array has nNormal elements. Does this mean the arrays can be of different lengths?

Vertex arrays in OpenGL has a 1:1 correspondence, meaning an index in one array MUST point to the corresponding information for that vertex in all arrays. With arrays of different lengths, this is not possible (for example, vertices in the end of the longest array will not have any corresponding information in the other arrays).

I have the solution right now, or almost this is what i think.
I must get per vertex data from Maya, instead of per Mesh data as i was doing.

This way i will have the information correctly and ready for glDrawElements(…).
At the end i will akomplish it!!! jijijij

Thanks.

Originally posted by Bob:
[b]You say the vertex array has nPos elements, and the normal array has nNormal elements. Does this mean the arrays can be of different lengths?

Vertex arrays in OpenGL has a 1:1 correspondence, meaning an index in one array MUST point to the corresponding information for that vertex in all arrays. With arrays of different lengths, this is not possible (for example, vertices in the end of the longest array will not have any corresponding information in the other arrays).[/b]