Skip to content


OBJ File Loader for OpenGL

In the followings a simple Obj File Loader using OpenGL ES will be described. For that, I used a structure to describe the mesh object:

typedef struct _ObjMesh { ObjVertex *m_aVertexArray; ObjNormal *m_aNormalArray; ObjTexCoord *m_aTexCoordArray; ObjFace *m_aFaces;

unsigned long int *m_aIndices; unsigned long int m_iNumberOfVertices,

m_iNumberOfNormals,
m_iNumberOfTexCoords,
m_iNumberOfFaces;

struct _ObjMesh *m_pNext; ObjFile m_iMeshID; unsigned char m_iMode; unsigned long int m_iDisplayListNum; } ObjMesh;

Each of the Vertices,Normals and Texture coordinates are also described in a structure:

typedef struct {

float x, /* The x component of the vertex position */
y, /* The y component of the vertex position */
z; /* The z component of the vertex position */

} ObjVertex;

typedef struct {

float x, /* The x component of the normal vector */
y, /* The y component of the normal vector */
z; /* The z component of the normal vector */

} ObjNormal;

typedef struct {

float u, /* The u parametric texturing co-ordinate */
v; /* The v parametric texturing co-ordinate */

} ObjTexCoord;

In the source file, each row of the file will be read in the loadFile(”file.obj”) method and the values will be recorderd in the structure. In order to draw the shape the DrawObj() method will be used.

Posted in Code Samples, Windows Mobile.


5 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. dicky says

    Hello Anca:

    I am a student. I am study on OpenGL ES now. I am interested in OBJ File Loader. Can you send me a simple source code to show this ? thanks. :)

    Mail: dickyfeng[at]gmail.com

  2. codetiger says

    fixed it myself. We used GLdrawelement() for opengl ES 1.1

  3. codetiger says

    Can you show me how to draw each triangle in OpenGL ES? Or how to draw the mesh?

  4. Anca A, says

    I think is already included in the source code.

  5. Jeffrey says

    Would you post the content of the “LoadFile” method as well?



Some HTML is OK

or, reply to this post via trackback.