Jump to content
  • Advertisement
Sign in to follow this  
j2900

Rendering wavefront obj files with VBOs

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

[color="#333333"]Here is an example wavefront obj file (I just quickly made it up) that I am trying to render using VBOs:
v 1 0 0
v 0 1 0
v 0 0 1

vt 0 0
vt 1 0

f 1/1 2/1 3/1
f 2/1 1/2 1/1

My vertex buffer contains {1,0,0,0,1,0,0,0,1} with stride sizeof(GLfloat)*3. That way, my index buffer is quickly generated as {1, 2, 3, 2, 1, 1} by just looking at the face definitions (and only looking at the vertex coordinate indices).

I'm not sure how to incorporate texture coordinates into this, as one vertex coordinate can map to multiple texture coordinates. I cannot draw from a texture coordinate buffer {0,0,1,0} with stride sizeof(GLfloat)*2 using the same element buffer that I use for my vertices.

I am unsure how to map each vertex to the correct texture coordinate in an efficient manner using VBOs. I believe interleaving would work with this format: {x, y, z, s, t}, and using an element buffer such as {0, 1, 2, 3, ...}, and doing a ton of copying of the vertices. However, this is not very efficient.

Also, as I'm new to this; is there a better format (than obj) I should be using?

Thanks.

Share this post


Link to post
Share on other sites
Advertisement

[color="#333333"]I am unsure how to map each vertex to the correct texture coordinate in an efficient manner using VBOs. I believe interleaving would work with this format: {x, y, z, s, t}, and using an element buffer such as {0, 1, 2, 3, ...}, and doing a ton of copying of the vertices. However, this is not very efficient.
[color="#333333"]


[color="#333333"]There is no way to make multiple mapping of indices. You will have to copy vertex data, there is no other way. But who on Earth told you this is "not efficient"? Rhetorical: why does everyone try to "optimize" something that wasn't even done yet?

[color="#333333"]

[color="#333333"]Also, as I'm new to this; is there a better format (than obj) I should be using?
[/quote]

That is the question for you to answer. There is no "the" format, never was, and never will be. Whatever suits you or your purpose should be fine.

Share this post


Link to post
Share on other sites
[color="#333333"]
Also, as I'm new to this; is there a better format (than obj) I should be using?


Production code usually uses custom file formats that are in binary and have their layout resembling the actual layout on GPU, because it's faster/easier to load. Ideally you should write exporters to popular modeling tools such as 3ds Max and Blender.

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!