# Sorting textures and vertex indices

## Recommended Posts

CRACK123    235
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 on other sites
zedzeek    529
(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 on other sites
CRACK123    235
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 ?

##### Share on other sites
zedzeek    529
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

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account