#include #include #include #include #include #include using namespace std; bool Scale_Translate; bool Do_None, Scale_Only, Translate_Only; struct VertexL { GLuint * verticies; int size; }; GLfloat * Points; vector Verticies; int Point_Count; void DrawText(void * font, string line) { int i; glPushMatrix(); glScalef(0.001, 0.001, 0.001); for(i=0; i < line.size(); i++) { glutStrokeCharacter(font, line[i]); } glPopMatrix(); return; } void WriteText(string message){ glPushMatrix() ; glTranslatef(-1.5, 1.5, 0); DrawText(GLUT_STROKE_ROMAN,message); glPopMatrix(); return; } void DoErrorReport() { GLenum err = GL_NO_ERROR; while ((err = glGetError()) != GL_NO_ERROR) { cout << "Got error " << err << endl; } } void display() { int i; glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // draw the axis glColor3f(0.0, 0.0, 0.0); glBegin(GL_LINES); glVertex3f(-1,0,0); glVertex3f(1,0,0); glVertex3f(0,-1,0); glVertex3f(0,1,0); glVertex3f(0,0,-1); glVertex3f(0,0,1); glEnd(); if (!Do_None) { if (Scale_Translate) { WriteText("Scale - Translate"); glScalef(.5,.5,.5); glTranslatef(-1,-1,-1); } else { WriteText("Translate - Scale"); glTranslatef(-1,-1,-1); glScalef(.5,.5,.5); } } else { if (Scale_Only) { WriteText("Scale Only"); glScalef(.5,.5,.5); } else if (Translate_Only) { WriteText("Translate Only"); glTranslatef(-1,-1,-1); } else { WriteText("Nothing"); } } glRotatef(-90, 1,0,0); glColor3f(1.0, 0, 0); for(i=0;i> Point_Count; Points = new GLfloat[Point_Count*3]; for(i=0;i> Points[i]; if (i==0) { max = Points[i]; min = Points[i]; } else { if (max < Points[i]) { max = Points[i]; } if (min > Points[i]) { min = Points[i]; } } } // center and scale everything. for(i=0;i> vertex; while (data) { tmp.verticies = new GLuint[vertex]; tmp.size = vertex; for(j=0;j> tmp.verticies[j]; } Verticies.push_back(tmp); data >> vertex; } data.close(); return; } void resize(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2, 2, -2, 2, -2, 2); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); return; } void keyInput(unsigned char key, int x, int y) { switch(key) { case '5': Scale_Translate = true; Do_None = false; break; case '4': Scale_Translate = false; Do_None = false; break; case '3': Do_None = true; Scale_Only = true; Translate_Only = false; break; case '2': Do_None = true; Scale_Only = false; Translate_Only = true; break; case '1': Do_None = true; Scale_Only = false; Translate_Only = false; break; case 27: case 'q': exit(0); break; default: break; } glutPostRedisplay(); return; } int main(int argc, char * argv[]) { string FileName = "cube.off"; if (argc > 1) { FileName = argv[1]; } ReadOff(FileName); glutInit(&argc, argv); glutInitContextVersion(3, 0); glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); glutInitWindowSize(500, 500); glutCreateWindow("Vertex Arrays"); glutDisplayFunc(display); glutReshapeFunc(resize); glutKeyboardFunc(keyInput); glewExperimental = GL_TRUE; glewInit(); setup(); glutMainLoop(); }