Sorting textures and vertex indices

Started by
2 comments, last by zedzeek 19 years, 8 months ago
Hi, Most of the modellers seem to export information of texture indices and vertex indices differently but however when the need to use vertex array comes in then glDrawElements would only take one set of indices. So how exactly would one go about rendering it in a vertex array ? Would you sort all the indices while loading ? How exaclty should one handle this ? Thanks
The more applications I write, more I find out how less I know
Advertisement
(is this the problem)
for each vertice u need a corresponding texture coordinate. often though for a vertice u want to have 2 or more texture coordinates/normals etc, thus in this case u will need to make 2 or more vertices (in the same place). ie there must be exactly the same number of vertices as texcoords/norms/colors etc.
float verts[] = { 0,0,0, 1,0,0, 2,3,2 };
float texcoords[] = { 0,0, 1,0, 1,1 };
so 3 verts = 3 texccords
so indice[2] = vert(2,3,2) + texccord(1,1)
Not really, thats not the problem. I will explain with an example.

Lets say I have vertices

-4.000000,-4.000000,-4.000000,4.000000,-4.000000,-4.000000,-4.000000,4.000000,-4.000000,4.000000,4.000000,-4.000000,-4.000000,-4.000000,4.000000,4.000000,-4.000000,4.000000,-4.000000,4.000000,4.000000,4.000000,4.000000,4.000000,


Now I have texture coordinates
0.619941,0.740010,0.619941,0.982984,0.378598,0.982984,0.378598,0.740010,0.378776,0.021546,0.620101,0.021546,0.620101,0.262185,0.378776,0.262185,0.138236,0.498979,0.378470,0.498979,0.378470,0.738238,0.138236,0.738238,0.862432,0.498810,0.862432,0.738837,0.618599,0.738837,0.618599,0.498810,0.378318,0.739578,0.378318,0.498601,0.619689,0.498601,0.619689,0.739578,0.378949,0.261777,0.620257,0.261777,0.620257,0.498426,0.378949,0.498426,


Now I have the vertex indices and texture indices respectively
vertex Indices0,2,3,0,3,1,0,1,5,0,5,4,0,4,6,0,6,2,1,3,7,1,7,5,2,6,7,2,7,3,4,5,7,4,7,6,texture indices0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23,


Now I have 2 sets of indices - 1 for textures an 1 for vertices. And if I do the following

glVertexPointer(3, float, 0, vector);glTexCoordPointer(2, float, 0, texture);glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, vertexIndices);OrglDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, textureIndices);


Now I have 2 different set of indices for textures and vertices. But I can only sent one set to opengl. So would I have to do some kind of reordering ?





The more applications I write, more I find out how less I know
read what i said here >>often though for a vertice u want to have 2 or more texture coordinates/normals etc, thus in this case u will need to make 2 or more vertices (in the same place).<<

thus u will need to go instead of
-4.000000,-4.000000,-4.000000,
4.000000,-4.000000,-4.000000,

say

-4.000000,-4.000000,-4.000000,
-4.000000,-4.000000,-4.000000, (duplicate)
-4.000000,-4.000000,-4.000000, (duplicate)
4.000000,-4.000000,-4.000000,
etc

This topic is closed to new replies.

Advertisement