Code:
struct md2Header {
int magic;
int version;
int skinWidth;
int skinHeight;
int frameSize;
int numSkins;
int numVertices;
int numTexCoords;
int numTriangles;
int numGlCommands;
int numFrames;
int offsetSkins;
int offsetTexCoords;
int offsetTriangles;
int offsetFrames;
int offsetGlCommands;
int offsetEnd;
};
struct md2cVert {
unsigned char Verts[3];
unsigned char LightNormalIndex;
};
struct md2Vert {
float Verts[3];
};
struct cTexCoords {
short s, t;
};
struct rTexCoords {
float s, t;
};
struct md2TrigInd {
short VertexIndicies[3];
short TextureIndicies[3];
};
struct md2Frame {
float Scale[3];
float Translate[3];
char Name[16];
md2cVert Verts[1];
};
struct md2Frame_t {
md2Vert *pVerts;
char Name[16];
};
struct md2Triangle {
float Verts[3];
float Normals[3];
};
There are my structures, perhaps somethign is wrong with them perhaps not.
Code:
FILE *pFile = fopen("tris.md2","rb");
md2Header Header;
md2Triangle *Triangles;
md2Frame *Frames;
cTexCoords *TexCoords;
fread(&Header,1,sizeof(md2Header),pFile);
Triangles = new md2Triangle[Header.numTriangles];
Frames = new md2Frame[Header.numFrames];
TexCoords = new cTexCoords[Header.numTexCoords];
fseek(pFile,Header.offsetTexCoords,SEEK_SET);
fread(TexCoords,sizeof(cTexCoords),Header.numTexCoords,pFile);
fseek(pFile,Header.offsetTriangles,SEEK_SET);
fread(Triangles,sizeof(md2Triangle),Header.numTriangles,pFile);
My loading Code (its in the winmain function as of now).
Now my rendering code:
Code:
glPushMatrix();
glScalef(.05f,.05,.05);
glBegin(GL_TRIANGLES);
for(int i = 0; i < Header.numVertices; i++) {
glTexCoord2f(TexCoords[i].s / Header.skinWidth,TexCoords[i].t / Header.skinHeight);
glVertex3f(((Frames[0].Verts[i].Verts[0] * Frames[0].Scale[0]) + Frames[0].Translate[0]),
((Frames[0].Verts[i].Verts[2] * Frames[0].Scale[2]) + Frames[2].Translate[2]),
((-1 * Frames[0].Verts[i].Verts[1] * Frames[0].Scale[1]) + Frames[1].Translate[1]));
}
glEnd();
glPopMatrix();
Edit: Sorry that I didn't post this before, but its a fair bit to look at, but if you see somethign wrong, please let me know.