Sign in to follow this  

OpenGL OBJ to indexed VBO

Recommended Posts

I'm having problems wrapping my head around on how to convert a OBJ file to a indexed interleaved VBO as OBJ uses separate indexes for vertex, normal, texcoords instead of just 1 for all as OpenGL. Now i only use the vertices and it loads and works great, but i need help on how to get vertex, normal and texcoords (using a single index).

Share this post

Link to post
Share on other sites
I'm afraid you will have to do a little more work in your Obj loading routines.
(Or of course, you could search for some Obj tool or source).
Anyway ... given a simple model that consists of a Vertex, tex coords and normals and a face index set you need to parse this into a vertex_array_friendly format.

The trick is to understand that the Obj file format is an optimized for storage format and not optimized for rendering. So - with that in mind you should essentially:

read the list of vertex coords and store in a temp vertex list
Do the same for the texture and normals
Then read each face in turn (and each face will have a set of indexes into the vertex, texture and normal temp lists). Use these indexes to obtain the corresponding vertex from the temp vertex list, the face-texture index to read the texture-coord from the temp texture list and so on for all the attributes. Finally, store the result into the Final_array_list and record the index in the final_index_list

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