Index/indices?

Started by
2 comments, last by iNsAn1tY 17 years, 1 month ago
So here I am, with my minimal graphics programming experience, coding small(ish) demos of some features such as odd physics (really odd "mess-with-your-mind" style), portals, etc. I'll later put them together, and -!-; a "mess-with-your-mind" game. Well, not exactly, but that's not the point. What I can't figure out is what an index is and how it's used to render things. I'm creating a custom scene node (in Irrlicht, but the engine doesn't really matter), and to render it my best choice is a triangle list. BUT - while I (mostly) know what the normals are and how to use them, etc., as well as the vertices and colors, I have no idea what the indices are. And the only triangle list option is a "indexedTriangleList". So, what I've come to ask you, Gamedevers, is what indices are and how I use them/figure them out? I've searched gamedev, google, wikipedia... Nothing exactly explaining indices came up. I dug through the source, found the GL source of the engine, found the indexedTriangle function, and read through the source. Found the main GL function, searched that, and came to some page that described EVERYTHING but what the indices are. These "indices" must probably be something really simple, and I'm probably just sort of "missing" the point (and thus not getting it)... but after all, I don't believe there are "stupid" questions (maybe stupid answers, yes), as with no matter how simple or odd a question is, the asker shall gain knowledge for the future, no? Anyone who responds (and actually helps [grin]) will be greatly THANKED! *cheers*, have a nice day!
Advertisement
Er, you didn't say which kind of indexes you meant. Are you talking about vertex indexes/indices? If so, an index is a reference to an entry in one or more array(s) of vertex attributes. An index array is exactly what the name suggests: an array of indices. Example:

// -------------------------// Vertex attribute streams// -------------------------float gfVertexPositions[]  = { -5.0f,  5.0f, 0.0f,      // Element 0                               -5.0f, -5.0f, 0.0f,      // Element 1                                5.0f, -5.0f, 0.0f,      // Element 2                                5.0f,  5.0f, 0.0f };    // Element 3float gfVertexNormals[]    = { 0.0f, 0.0f, 1.0f,        // Element 0                               0.0f, 0.0f, 1.0f,        // Element 1                               0.0f, 0.0f, 1.0f,        // Element 2                               0.0f, 0.0f, 1.0f };      // Element 3// ----------------// The index array// ----------------unsigned short guMeshIndices[] = { 0, 1, 3,                                   1, 2, 3 };

guMeshIndices is an index array that specifies two triangles: one which uses elements 0, 1 and 3 from the positions and normals arrays, and one which uses elements 1, 2 and 3. The index array is one of the parameters you specify to glDraw[Range]Elements, which actually does the drawing when you're using vertex attribute and index arrays. Have a look at the glVertexPointer, glNormalPointer and glEnableClientState functions for more.

Or did you mean the values you specify to glIndexPointer? To be honest, I'm not entirely sure what they do at all. Never used 'em.

[Edited by - iNsAn1tY on March 4, 2007 7:15:11 PM]
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
Quote:Original post by iNsAn1tY
Er, you didn't say which kind of indexes you meant. Are you talking about vertex indexes/indices? If so, an index is a reference to an entry in one or more array(s) of vertex attributes. An index array is exactly what the name suggests: an array of indices. Example:

*** Source Snippet Removed ***
guMeshIndices is an index array that specifies two triangles: one which uses elements 0, 1 and 3 from the positions and normals arrays, and one which uses elements 1, 2 and 3. The index array is one of the parameters you specify to glDraw[Range]Elements, which actually does the drawing when you're using vertex attribute and index arrays. Have a look at the glVertexPointer, glNormalPointer and glEnableClientState functions for more.

Or did you mean the values you specify to glIndexPointer? To be honest, I'm not entirely sure what they do at all. Never used 'em.


Wow, thanks a bunch for the swift and accurate reply, mate! Greatly appreciated! (I'll attempt a rate++, not sure how much it'll affect you, but hey [grin]...)

So, let me just get this straight - indices tell the function which ... "set" vertices and normals to use? So if you have a vertex array of 18 floats:
float v[] ={    1.0, 2.0, 3.0,    3.0, 4.0, 5.0,    1.0, 2.0, 3.0,    3.0, 4.0, 5.0,    1.0, 2.0, 3.0,    3.0, 4.0, 5.0};

Having a index array of:
int i[] = {0, 3, 4};

Will draw a triangle with these vertices:
v1: 1.0, 2.0, 3.0v2: 1.0, 2.0, 3.0v3: 3.0, 4.0, 5.0

?

Thanks a bunch man!
Quote:Original post by agi_shi
Quote:Original post by iNsAn1tY
Er, you didn't say which kind of indexes you meant. Are you talking about vertex indexes/indices? If so, an index is a reference to an entry in one or more array(s) of vertex attributes. An index array is exactly what the name suggests: an array of indices. Example:

*** Source Snippet Removed ***
guMeshIndices is an index array that specifies two triangles: one which uses elements 0, 1 and 3 from the positions and normals arrays, and one which uses elements 1, 2 and 3. The index array is one of the parameters you specify to glDraw[Range]Elements, which actually does the drawing when you're using vertex attribute and index arrays. Have a look at the glVertexPointer, glNormalPointer and glEnableClientState functions for more.

Or did you mean the values you specify to glIndexPointer? To be honest, I'm not entirely sure what they do at all. Never used 'em.


Wow, thanks a bunch for the swift and accurate reply, mate! Greatly appreciated! (I'll attempt a rate++, not sure how much it'll affect you, but hey [grin]...)

So, let me just get this straight - indices tell the function which ... "set" vertices and normals to use? So if you have a vertex array of 18 floats:
float v[] ={    1.0, 2.0, 3.0,    3.0, 4.0, 5.0,    1.0, 2.0, 3.0,    3.0, 4.0, 5.0,    1.0, 2.0, 3.0,    3.0, 4.0, 5.0};

Having a index array of:
int i[] = {0, 3, 4};

Will draw a triangle with these vertices:
v1: 1.0, 2.0, 3.0v2: 1.0, 2.0, 3.0v3: 3.0, 4.0, 5.0

?

Thanks a bunch man!

Yup, you got it. In your example, v basically holds 6 vertices with (x, y, z) coords. Slight typo in your example above, corrected below:

Will draw a triangle with these vertices:
v1: 1.0, 2.0, 3.0v2: 3.0, 4.0, 5.0  // <- These two were thev3: 1.0, 2.0, 3.0  // <- wrong way round :)
Thx for the rating++, always appreciated [smile].
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]

This topic is closed to new replies.

Advertisement