#ifndef _OBJLOADER_H_ #define _OBJLOADER_H_ extern char ObjLastFname[101]; typedef struct { float x, y, z, w; } ObjVertex; typedef struct { float x, y, z; } ObjNormal; typedef struct { float s, t, r, q; } ObjTexCoord; typedef struct { unsigned int Vertex[4]; unsigned int Normal[4]; unsigned int TexCoord[4]; } ObjFace; typedef struct { char *map_Ka; char *map_Kd; ObjVertex Tf; ObjVertex Ka; ObjVertex Kd; ObjVertex Ks; ObjVertex Ke; float Ns; float Ni; float d; float Tr; int illum; } ObjMtl; typedef struct { char *objectName; char *groupName; char *usemtl; ObjMtl *mtl; ObjVertex *VertexArray; ObjNormal *NormalArray; ObjTexCoord *TexCoordArray; ObjFace *FaceArray; unsigned nVertex, nNormal, nTexCoord, nFace; char *mtllib; } ObjModel; /* function prototypes */ ObjModel *ObjLoadModel(char *, size_t); /* read a file into argument 2, and return amount of bytes read */ size_t ObjLoadFile(char *, char **); void ObjList(ObjModel *); /* once we load an .obj file, we can extract path up to last '/' to load a * mtl or texture that resides in the same folder */ char *ObjGetPath(const char *); void ObjSubmitIndexedVertexArrayQuad(const ObjModel *); void ObjSubmitGLCommandsQuad(const ObjModel *); void ObjSubmitGLCommandsTriangle(const ObjModel *); void ObjFree(ObjModel *); static inline ObjNormal *ObjGetNormal(const ObjModel *model, const unsigned i, const unsigned j) { return &(model->NormalArray[model->FaceArray[i].Normal[j] - 1]); } static inline ObjTexCoord *ObjGetTexCoord(const ObjModel *model, const unsigned i, const unsigned j) { return &(model->TexCoordArray[model->FaceArray[i].TexCoord[j] - 1]); } static inline ObjVertex *ObjGetVertex(const ObjModel *model, const unsigned i, const unsigned j) { return &(model->VertexArray[model->FaceArray[i].Vertex[j] - 1]); } #endif