Jump to content
  • Advertisement
Sign in to follow this  
havok4567

OpenGL Displaying models with vertex arrays

This topic is 3662 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've just started trying to use vertex arrays as opposed to immediate mode and i'm confused about what the best way is now to display a 3D model. If I am loading a .obj file I get an array of vertices and normals and a list of triangles saying how the vertices and normals match up. With immediate mode I would have done something like iterate through the list of triangles and call glVertex for the vertices listed and glNormal for the normals. This way they would have been in the correct order and set in the .obj file. But now I just pass OpenGL the list of vertices and normals but it is missing the extra triangle information to work out how they match up so do I have to cleverly order the two arrays based on the triangle information? Or is there a bit more to it. I'm a bit confused and would appreciate some help, cheers.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by havok4567
But now I just pass OpenGL the list of vertices and normals but it is missing the extra triangle information to work out how they match up so do I have to cleverly order the two arrays based on the triangle information? Or is there a bit more to it. I'm a bit confused and would appreciate some help, cheers.
Yes, you need to rebuild the vertex, normal and texture coordinate arrays to match the triangle information in the .obj faces list. This process is often called 'vertex welding', which ought to bring up a few hits on google.

Share this post


Link to post
Share on other sites
Cheers man, yeah i've been searching for a while but without the right jargon it's not always easy :) Thanks a lot, I love how fast the responses on these forums always are!

EDIT: Okay i've got a really simple .obj loader going and its a great feeling :) I ended up loading in a list of vertices, normals and faces then iterating over the list of faces and adding each vertice into a vertex array and the normals into a normal array. This means that the normals and vertices are in the correct order and match up so the model displays and looks good but i'm not sure if it could be improved by getting rid of repeated vertices?

EDIT 2: I have been reading up more and found a function "glDrawElements" which I hadn't seen before. I'm really new to this whole vertex array things and I had found a site which taught me to use "glDrawArrays". So from what I gather with "glDrawArrays" you use it just how I have, have a long list of vertices that may repeat - easy to code but wastes on memory and probably transfers to the gpu. But i'll look into "glDrawElements" as it seems like a more elegant solution.

[Edited by - havok4567 on November 30, 2008 11:18:40 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by havok4567
This means that the normals and vertices are in the correct order and match up so the model displays and looks good but i'm not sure if it could be improved by getting rid of repeated vertices?

But i'll look into "glDrawElements" as it seems like a more elegant solution.
You can use glDrawElements() to solve the duplicate vertex problem - just build indices from your new vertex array, and when you hit a repeated vertex, remove the vertex and index the first copy.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!