Sign in to follow this  

(VBO)moving from glDrawArrays to glDrawElements

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

Hey. im trying to get glDrawElements working in my engine. So far the shapes of my objects are correct but the texture coords and normals are messed up. i dont understand what i should do with texture coords and normals when using glDrawElements. some of the turorials i read stated (as far as i understand) that your indices array also points to your normal and texture coords the same way it points to your vertices and that if you have 2 points from 2 diferent triangles with the same position but different normals/tex coords you have to store them seperatley. I dont see how this can be right? wouldnt that completely defeat the purpose? sure i understand that i need to store the normals and tex coords seperatley but why the vertices if its the same?. why bother sending the indices array over with each call if its only going save on points with the same position, texture coords and normals... on a typical model adjescent polygons that share points usualy have at least different normals so i dont see how glDrawElements would help at all. What am i misunderstanding here? Thnx in Advance!

Share this post


Link to post
Share on other sites
Consider a cube. It has 8 vertices and each vertex is shared among 3 faces. So you can share vertices, but you cannot share the normals, as each vertex for each face is different. So you duplicate vertices so the normals can be specified, and you end up with 24 vertices.

Consider instead a sphere, highly tessellated. Each vertex may be shared among neighboring faces, but since the sphere is smooth, the normal for a vertex will be the same for every face. So in this case, you don't have ti duplicate anything, because the sphere is smooth and shared vertices all have the same attributes for all faces.

For a smooth geometry, shared vertices generally have all attributes the same. Sharp geometry generally need duplication as attributes, primarily the normal, will be different. So for smooth geometry, you will have a lot of shared vertices and benefit from indexed vertex arrays.

Share this post


Link to post
Share on other sites
kk thnx for clearing that up. but what should i then use? should i just use glDrawElements for everything anyway or would it be best to implement both and load my models diferently? since one model might consist of a lot more smooth surfaces that another

Share this post


Link to post
Share on other sites

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

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

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this