Advertisement Jump to content
Sign in to follow this  

How do I use face data in an OBJ file ?

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

After watching this tutorial by the coding universe (

), I am confused as to what face data (denoted by an f at the start of the line) in a .obj file is, and how it is supposed to be used.


As an exercise to try and find this out for myself, I experimented and wrote a parser for an obj file in java, that only loaded the vertex and normal data from the Stanford bunny model. I rendered it using glDrawArrays, but it came out contorted, with lines connecting triangles that shouldn't be connected.


It looked like this:


You can just see the basic shape of the bunny under all the stuff that isn't meant to be there.


Do I need the face data to render the model ? Can you do it without it ? If so how do you use it and what does it mean ?

Share this post

Link to post
Share on other sites
The face data defines which vertices make up each triangle in the model.

For example:
f 1 2 3
Defines a triangle made from the 1st, 2nd and 3rd vertices.

Ideally, you load all the vertices from the obj file into a single vertex array, and then load all the faces into an index array, for use with glDrawElements().

Unfortunately, things get significantly more complicated if you happen to have an obj file with normals and/or texture coordinates, because the face definition will give you an index for each. You pretty much have to build up all combinations of vertex/texcoord/normal, and remove the duplicates afterwards (regenerating the index array as you go). Edited by swiftcoder

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!