#ifndef __STKGL_H_ #define __STKGL_H_ #include typedef float sk1Vertex[3]; typedef float sk1Color[3]; typedef struct { int vertices; // defines how many lines of vertices int colors; //how many lines will have color codes int colorSkip; // defines how many lines before the colors begin e.g. after 3 lines of vertices, start 1 line of color sk1Vertex *mdlVert; sk1Color *mdlColor; }model; class STKGL { public: void DrawScene(void (*p)()); model *TriangleLoad(model *tem, char *Filename); void DrawTriangle(model*); STKGL() {;}; ~STKGL() {;}; sk1Vertex *t; sk1Color *p; }; void STKGL::DrawScene(void (*p)()) { (*p)(); } model *STKGL::TriangleLoad(model *tem, char *Filename) { STKGL *Ctemp; ZeroMemory(tem, sizeof(model)); int skipNum = 0; int colNum; FILE *fptr, *fOut; fptr = fopen(Filename, "rb"); fscanf(fptr, "%d", &tem->vertices); fscanf(fptr, "%d", &tem->colors); fscanf(fptr, "%d", &tem->colorSkip); //sk1Vertex *mdlVert = new sk1Vertex[tem->vertices]; tem->mdlVert = new sk1Vertex[tem->vertices]; tem->mdlColor = new sk1Color[tem->colors]; for(int v = 0; v <= tem->vertices-1; v++) { fscanf(fptr, "%f %f %f", &tem->mdlVert[v][0], &tem->mdlVert[v][1], &tem->mdlVert[v][2]); } for(int c = 0; c <= tem->colors-1; c++) { fscanf(fptr, "%f %f %f", &tem->mdlColor[c][0], &tem->mdlColor[c][1], &tem->mdlColor[c][2]); } fclose(fptr); return tem; } void STKGL::DrawTriangle(model *tem) { int colNum = 0; static float x = 0.5f; int skipNum = 1; int n = 0; glRotatef(x, 0.5f, 0.5f, 0.0f); glBegin(GL_TRIANGLES); for(n = 0; n <= tem->vertices-1; n++) { glColor3f(1.0f, 1.0f, 1.0f); if(colNum != tem->colors) { if(skipNum == tem->colorSkip) { glColor3f(tem->mdlColor[colNum][0], tem->mdlColor[colNum][1], tem->mdlColor[colNum][2]); glVertex3f(tem->mdlVert[n][0], tem->mdlVert[n][1], tem->mdlVert[n][2]); colNum++; skipNum = 1; } else { glVertex3f(tem->mdlVert[n][0], tem->mdlVert[n][1], tem->mdlVert[n][2]); } } else{ glVertex3f(tem->mdlVert[n][0], tem->mdlVert[n][1], tem->mdlVert[n][2]); } skipNum++; } glEnd(); x+=0.03f; } #endif