Jump to content
  • Advertisement
Sign in to follow this  
CyberSlag5k

Using indexed mesh data with glDrawElements*()

This topic is 4981 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 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...?

Share this post


Link to post
Share on other sites
Advertisement
You just need to call glVertexPointer, glNormalPointer, and if you're using textures, glTexCoordPointer

They should have these functions listed in the book.

Share this post


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

Share this post


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

Share this post


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

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!