Sign in to follow this  
j2900

Rendering wavefront obj files with VBOs

Recommended Posts

j2900    100
[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.[/color]

Share this post


Link to post
Share on other sites
capricorn    139
[quote name='j2900' timestamp='1312487784' post='4844659']
[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][color="#333333"][/quote][/color]

[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]

[color="#333333"][quote][/color]
[color="#333333"]Also, as I'm new to this; is there a better format (than obj) I should be using?[/color]
[/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
EngineCoder    246
[quote name='j2900' timestamp='1312487784' post='4844659'][color="#333333"]
Also, as I'm new to this; is there a better format (than obj) I should be using?
[/color][/quote]

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
V-man    813
As was already explained about file format by previous poster
[url="http://www.opengl.org/wiki/FAQ#What_3D_file_format_should_I_use.3F"]http://www.opengl.or...should_I_use.3F[/url]

and the problem of indices and the OBJ format
http://www.opengl.org/wiki/FAQ#Multi_indexed_rendering

Share this post


Link to post
Share on other sites

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