Jump to content
  • Advertisement
Sign in to follow this  
eOgas

OpenGL Using glNormalPointer with glDrawElements

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

Hi. I recently started writing a loader for 3ds files, but unfortunately I haven't been able to find any information at all on how to interpret the information on smoothing groups. This led me to attempt to calculate and render my own normals. Checking my values at a breakpoint, the normals are correct. The only problem is that glDrawArrays seems to be picking them completely at random. I've got a faces[] array that holds the indices for accessing the verts[] array. This is fed into glDrawElements. I figured opengl would traverse my normal array in order, but that does not seem to be the case. It also does not seem to be the case that the indices are used on the normal array as well. Does anyone know what method it uses to traverse the normal array? I can't find any information on the web.

Share this post


Link to post
Share on other sites
Advertisement

for (int i = 0; i < [objects count]; i++)
{
glVertexPointer(3, GL_FLOAT, 0, [[objects objectAtIndex:i] verts]);
glNormalPointer(GL_FLOAT, 0, [[objects objectAtIndex:i] norms]);
glDrawElements(GL_TRIANGLES, [[objects objectAtIndex:i] numFaces] * 3,
GL_UNSIGNED_SHORT, [[objects objectAtIndex:i] faces]);


}




objects is just an array of, well objects, defined by the 3ds file. Each contains a verts array of vertices, a norms array of normals, and a faces array which holds the indices for the verts.

Share this post


Link to post
Share on other sites
normals and vertices go together. The same index is used for both.
Don't forget to call glEnableClientState(GL_NORMAL_ARRAY).

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!