AncaA's tech journal

17 Jan, 2008

OBJ File Loader for OpenGL

Posted by: Anca Alimanescu In: OpenGL| OpenGL ES

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.

  • Share/Bookmark

5 Responses to "OBJ File Loader for OpenGL"

1 | Jeffrey

July 1st, 2008 at %I:%M %p

Avatar

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

2 | Anca A,

July 8th, 2008 at %I:%M %p

Avatar

I think is already included in the source code.

3 | codetiger

October 14th, 2008 at %I:%M %p

Avatar

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

4 | codetiger

October 14th, 2008 at %I:%M %p

Avatar

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

5 | dicky

October 15th, 2008 at %I:%M %p

Avatar

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

Comment Form

Arhive

Mobile Barcode

qrcode

This is a 2D-barcode containing the address of my mobile site.If your mobile has a barcode reader, simply snap this bar code with the camera and launch the site.

About me

Client-focused software engineer with high intellectual mobility and experience in international teams.

Some of my interests are open innovation, design patterns, networking, personal branding, blogging and study of foreign languages.

Enjoy your visit and don’t hesitate to leave me a feedback!


Software entropy

1. A computer program that is used will be modified.

2. When a program is modified, its complexity will increase, provided that one does not actively work against this.

Switch to our mobile site