Hi guys,
I was wondering if could get some help please?
I’ve exported an OBJ file from 3ds max with the vertex, vertex normal and texture coord data included. In the exported file, each entry is listed in its respective list, thus:
v -10.0000 0.0000 10.0000 //vertex 1; x,y,z
v 10.0000 0.0000 10.0000 // vertex 2
v -10.0000 0.0000 -10.0000 // etc
vn 0.0000 -1.0000 -0.0000 // normal 1; x,y,z
vn 0.0000 1.0000 -0.0000 // normal 2
vn 0.0000 1.0000 -0.0000 // etc
and then underneath the triangles are specfied using the format:
f v(x)/vt(x)/vn(x), v(x)/vt(x)/vn(x), v(x)/vt(x)/vn(x)
…where x is the list lookup index, and v,t and n are the vertex, texture coord and normal lists.
I’ve filtered out the irrelevant data using another program, in order to provide 3x 3d-coordinate arrays for OpenGL, called vertlist, normlist and texlist. I’ve also transferred the index list into an array of GLunits called trilist.
When it comes to glDrawElements I’m having trouble, because it only accepts one set of indices, and I need 3, because my model has 8 verts, 12 vt’s and 36 vn’s and therefore the values don’t correspond in any way.
My code looks like this:
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertList);
glNormalPointer(3, GL_FLOAT, 0, normList);
glTexCoordPointer(3, GL_FLOAT, 0, texList);
glDrawElements(GL_TRIANGLES, TRIANGLECOUNT * 3 , GL_UNSIGNED_INT, triList); // < problem here
The only other way I can imagine to do it is to avoid indices altogether, and have three separate same-size arrays with corresponding v, vt and vn data. But this would seem wasteful as I would have to duplicate vertex and texture information to match the number of normals in the scene. Not to mention that this would be slower.
Is this a common problem in OpenGL? Any suggestions for a workaround would be very welcome.
Many thanks,
Neil