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.
