• Advertisement
Sign in to follow this  

Sorting textures and vertex indices

This topic is 4944 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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 Indices
0,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 indices
0,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);

Or

glDrawElements(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 ?





Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement