#include #include #include #include #include #include using namespace std; int AXIS_INDEX[] = {0,1,2,3,4,5}; float XRot, YRot, ZRot; struct VertexL { GLuint * verticies; int size; }; GLuint **indicies; GLsizei * count; GLfloat * Points; int Point_Count; int Polygon_Count; 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(); glRotatef(XRot, 1,0,0); glRotatef(YRot, 0,1,0); glRotatef(ZRot, 0,0,1); glMultiDrawElements(GL_TRIANGLE_FAN, count, GL_UNSIGNED_INT, (const GLvoid **) indicies, Polygon_Count); glFlush(); DoErrorReport(); return; } void reset() { XRot = 0; YRot = 0; ZRot = 0; } void setup() { reset(); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(3, GL_FLOAT, 6*sizeof(GLfloat), Points); glColorPointer(3, GL_FLOAT, 6*sizeof(GLfloat), Points+3); glClearColor(1.0,1.0, 1.0, 0.0); return; } void ReadPoint(ifstream & data, GLfloat & point, GLfloat & max,GLfloat & min){ static bool first=true; data >> point; if (first) { max = point; min = point; first = false; } else { if (max < point) { max = point; } if (min > point) { min = point; } } return; } void ReadOff(string FileName) { ifstream data; int i,j; int vertex; float max, min; vector Verticies; data.open(FileName.c_str()); data >> Point_Count; Points = new GLfloat[Point_Count*6]; 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(); // global for the count Polygon_Count = Verticies.size(); // grab a vector for the count; count = new GLsizei[Polygon_Count]; // make a matrix for each polygon index list. indicies = new GLuint*[Polygon_Count]; // copy these over. // It would be easier if we knew the count before we processed the array // We could process the file twice I suppose. We then would not have to // have the object in memory twice. for(i=0;i 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(); }