Jump to content
  • Advertisement
Sign in to follow this  
Tera_Dragon

Vertex Array Indices.

This topic is 4989 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

I've read a couple of tutorials on vertex arrays, but i just don't understand the index. Could someone explain about it and how to calculate it. I'm sorry but I can't really give you more info than that. I just don't get the index. Tera_Dragon

Share this post


Link to post
Share on other sites
Advertisement
I have a simmilar problem to you. Although, i think the indicies are the numbers in the arrays.
(Plz correct mr if im wrong)

Verticies[10];
Colors[10];

If you have verticies from 0-10, then thats your start and finish indicies, or something.

Share this post


Link to post
Share on other sites
For example:
glTexCoordPointer(2,GL_FLOAT,0,&texCoords);
glVertexPointer(3,GL_FLOAT,0,&vertices);
glbindTexture(GL_TEXTURE_2D,skyTexture);
glDrawElements(GL_TRIANGLES,length(indices),GL_UNSIGNED_INT,&indices);

The texCoords array is an array of floats. The first two elements are the u and v-coordinate of your first point. The second two elemtents are the u end c-coordinate of your second point,...
texCoords[0] = u1;
texCoords[1] = v1;
texCoords[2] = u2;
texCoords[3] = v2;
...

The vertices array is also an array of floats. This array contains the x,y and z-coordinates.
vertices[0] = x1;
vertices[1] = y1;
vertices[2] = z1;
vertices[3] = x2;
vertices[4] = y2;
vertices[5] = z2;
...

The indices array contains the indices to the texCoords and the vertices array. For example;
indices[0] = 0;
indices[1] = 1;
indices[2] = 2;

This will draw a triangle between (x1,y1,z1) and (x2,y2,z2) and (x2,y2,z2) with uv-coordinates (u1,v1) and (u2,v2) and (u3,v3).

Share this post


Link to post
Share on other sites
So there is one index for each vertex?
Can you see why this crashes:

int indices[3]; //global
...
for(int i = 0; i < 3; i++) // this works if i<4 is used.
indices = i;
...
glDrawElements(GL_TRIANGLES, 9, GL_UNSIGNED_INT, indices);

Thanks for the help so far.
Tera_Dragon

Share this post


Link to post
Share on other sites
no, infact, its (numberOfPolygons * numberOfVertsPerPolygon)
so for triangles: (numTris * 3)

i'm going to try and explain indicies for you, sorry if i confuse you :(


suppose you have a quad that is made up of 2 triangles

0 1
+---------------+
|\ |
| \ B |
| \ |
| \ |
| \ |
| A \ |
| \ |
| \|
+---------------+
3 2


now the '+' signs are our verticies. you see how triangle 'A' and triangle 'B' share vertex numbers 0 and 2?

this is what indexes are for, we dont want to specifiy vertex number 0 and 2 each twice (once for each polygon) so we use indexes.

so to rendering triangle A we would use these verticies:
(0, 2, 3)

and to render triangle B we would use these verticies:
(0, 1, 2)

now you notice that we have 6 index's and only 4 vertices.
2 triangles, each with 3 verticies = 6 index's.

Share this post


Link to post
Share on other sites
I'm now using 2 triangles and things are getting really confusing. I am using triangle strips and just don't understand how I should set out the vertices to make the triangles you drew. I first used 6 vertices, but now I think I may only have to use 4. How should I set out the vertices and indices? I've just spend about 30 mins messing about with a load of vertices and have just ended up even more confused than when I started. Please help to get this sorted out in my brain! ;-)
Tera_Dragon

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!