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.


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.


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!


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