Using indexed mesh data with glDrawElements*()

Started by
3 comments, last by CyberSlag5k 19 years, 1 month ago
I have a triangle mesh with surface normals stored in an indexed array of triangle objects. Is this the ideal way to use glDrawElements*()? I'm looking at the vertex array section of the redbook (v1.2) but I don't see where they reference the actual data using the indexed array. They have the following: static GLubyte allIndices[] = {4, 5, 6, 7, 1, 2, 6, 5, ...} glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, allIndices); I don't see in there where glDrawElements is given the actual data referenced by allIndices. Is this done in the array setups? Using glIndexPointer perhaps? If so, how is that function used? Does its third parameter take a pointer to the true vertex data that the indexed array references? Or does glVertexPointer somehow do that? I'm a little confused on how to set the arrays up to point to my data. I assume that the indexed array is preferable to work with, but I just don't see how it is used properly. EDIT: Sudden (potential) revelation. I pass my vertex data to glVertexPointer() and the indexed array to glIndexPointer()? Then I also pass the indexed array to glDrawElements...?
Without order nothing can exist - without chaos nothing can evolve.
Advertisement
You just need to call glVertexPointer, glNormalPointer, and if you're using textures, glTexCoordPointer

They should have these functions listed in the book.
Author Freeworld3Dhttp://www.freeworld3d.org
Quote:Original post by CyberSlag5k
EDIT: Sudden (potential) revelation. I pass my vertex data to glVertexPointer() and the indexed array to glIndexPointer()? Then I also pass the indexed array to glDrawElements...?

Almost correct. The vertex data is indeed passed to glVertexPointer, and the index array is passed to glDrawElements. However, glIndexPointer is used for color indices, and not the index array. glIndexPointer is the same as glColorPointer, but is used for indexed colors instead of RGBA colors.
Quote:Original post by oconnellseanm
You just need to call glVertexPointer, glNormalPointer, and if you're using textures, glTexCoordPointer

They should have these functions listed in the book.


Right, I know how the vertex arrays work (for the most part, I haven't implemented them yet). My question is, how do I specify an index to my vertex data? Is that what glIndexPointer() is used for?

Ok, let me clarify. I have my mesh of vertices and normals. I also have a struct:

struct I_Tri:
{
unsigned short int x, y, z;
vector normal;
}; *indexPtr;

Those values, x, y, and z reference an array of unique vertices for my mesh. Can I pass this indexed data to the vertex array somehow? Would that not be more efficient than just passing bulk vertex data? Or does it not matter?
Without order nothing can exist - without chaos nothing can evolve.
Quote:Original post by Brother Bob
Quote:Original post by CyberSlag5k
EDIT: Sudden (potential) revelation. I pass my vertex data to glVertexPointer() and the indexed array to glIndexPointer()? Then I also pass the indexed array to glDrawElements...?

Almost correct. The vertex data is indeed passed to glVertexPointer, and the index array is passed to glDrawElements. However, glIndexPointer is used for color indices, and not the index array. glIndexPointer is the same as glColorPointer, but is used for indexed colors instead of RGBA colors.


So the data I pass to glVertexPointer() will be referenced using the list of indices I pass glDrawElements then? That makes sense. Thank you.
Without order nothing can exist - without chaos nothing can evolve.

This topic is closed to new replies.

Advertisement