Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using GLFW and I want to draw a obj file. How are they drawn? I know how to draw 3D in OpenGL but when I open the obj file I see "v"s, "vn"s, "f"s, "vt"s, what are these? I don't know how to read these file types. Help? Thanks in advanced!


I can't find anything helpful online, that's why I'm asking this here.

share|improve this question

closed as not constructive by msell, Byte56, bummzack, Maik Semder, sam hocevar May 28 '13 at 10:01

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

First hit from Google for ".obj file format": – msell May 18 '13 at 11:37
up vote 1 down vote accepted

There is a good documentation on Wikipedia. The format is made by Wavefront, you'll find lot more information online with this name. This is the Wikipedia article.

Basically, v means vertex position, vt means texture coordinate and vn means vertex normal. f defines indices of a face.

It isn't that easy to draw *.obj models in a modern way, since their indexing works different from how OpenGL buffers work. In an *.obj file, indices (faces) point to a position, a normal and a texture coordinate separately. In OpenGL instead, an index is expected to point at at a single position in all those attributes at once.

I struggled with the format for some weeks and then decided to use the great loader Assimp which supports *.obj and *.3ds among many others. You may consider to use that library from the beginning.

share|improve this answer

The problem with the obj format is that it isn't standardised. So you'll see some that use clockwise winding (not good for a naive implementation in OpenGL) some that use counter-clockwise winding (not good for a naive implementation in DirectX) plus all other kinds of quirks that are vendor-dependent (eg. triangles vs quads as primitives).

The most usual implementation is an index based list.

v starts a line that contains information referring to vertices' geometry (their position, with 3 coordinates).

The next type of starts with vt followed by two numbers referring to texture coordinates.

The last type is vn which contains the normal vector for every vertex (useful for Gouraud or Phong shading).

The last important part starts with f, meaning face. Usually these are triangles but you may encounter quads. Lines that start with f may look like this : f 1/1/1 2/2/2 3/5/3.

That means you have three vertices: 1st vertex uses the position on the first line that starts with V , the texture coordinates on the 1st line that starts with vt and so on for vn.

The third index uses the information referenced in the fifth line that uses vn, while the other two paramters are from their respective third lines.

Knowing this, it is very easy to make an OBJ parser that reads such files, as long as you keep it simple and don't try to cover all cases (clock-wise counterCW , quds vs triangles) and so on.

Have fun!

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.