#include #include #include #include #include using namespace std; struct PointT { GLfloat data[3]; }; // these are the points to make up the circle vector points; // The number of points in the circle int Circle_Points; GLenum Shape_Mode; float Center_X, Center_Y; float X_Min, X_Max, Y_Min, Y_Max; void RedoViewport(void); // Drawing routine. void drawScene(void) { int i; glClear(GL_COLOR_BUFFER_BIT); glColor3f(0,0,0); glBegin(GL_POLYGON); glVertex2f(0,0); glVertex2f(0,100); glVertex2f(100,100); glVertex2f(100,0); glEnd(); // this is just a box for reference. glColor3f(1.0,0.0,0.0); glBegin(Shape_Mode); for(i=0;i h) { min = h; } glViewport(0, 0, min, min); RedoViewport(); return; } void NextShape() { cout << "The shape is now "; switch(Shape_Mode) { case GL_POLYGON : Shape_Mode = GL_POINTS; cout << "Line Points"; break; case GL_POINTS : Shape_Mode = GL_LINES; cout << "Line Lines"; break; case GL_LINES: Shape_Mode = GL_LINE_STRIP; cout << "Line Strip"; break; case GL_LINE_STRIP: Shape_Mode = GL_LINE_LOOP; cout << "Line Loop"; break; case GL_LINE_LOOP: Shape_Mode = GL_TRIANGLES; cout << "Triangles"; break; case GL_TRIANGLES: Shape_Mode = GL_TRIANGLE_STRIP; cout << "Triangle Strip"; break; case GL_TRIANGLE_STRIP: Shape_Mode = GL_TRIANGLE_FAN; cout << "Triangle Fan"; break; case GL_TRIANGLE_FAN: Shape_Mode = GL_QUADS; cout << "Quads "; break; case GL_QUADS: Shape_Mode = GL_QUAD_STRIP; cout << "Quad Strip"; break; case GL_QUAD_STRIP: default: Shape_Mode = GL_POLYGON; cout << "Polygon"; } cout << endl; return; } // Keyboard input processing routine. void keyInput(unsigned char key, int x, int y) { bool redisplay = true; int i; static bool fill=false; switch(key) { case 'l': X_Min -= 10.0; Y_Min -= 10.0; RedoViewport(); break; case 'L': X_Min += 10.0; Y_Min += 10.0; RedoViewport(); break; case 'u': X_Max -= 10.0; Y_Max -= 10.0; RedoViewport(); break; case 'U': X_Max += 10.0; Y_Max += 10.0; RedoViewport(); break; case 'x': Center_X -= 10; MakePoints(); break; case 'X': Center_X += 10; MakePoints(); break; case 'y': Center_Y -= 10; MakePoints(); break; case 'Y': Center_Y += 10; MakePoints(); break; case 'r': reset(); break; case 's': NextShape(); break; case 'P': Circle_Points ++; MakePoints(); break; case 'm': fill = !fill ; if (fill) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE ); } else { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL ); } case 'p': if (Circle_Points > 4) { Circle_Points --; MakePoints(); } break; case 'q': case 'Q': case 27: redisplay = false; exit(0); break; default: redisplay = false; cout << "Keypress " << key << " does not have an assigned action " << endl; break; } if (redisplay) { glutPostRedisplay(); } } // Main routine. int main(int argc, char **argv) { glutInit(&argc, argv); glutInitContextVersion(3,0); glutInitContextProfile(GLUT_CORE_PROFILE); //glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); glutInitWindowSize(500, 500); glutCreateWindow("My Circle"); glutDisplayFunc(drawScene); glutReshapeFunc(resize); glutKeyboardFunc(keyInput); glewExperimental = GL_TRUE; glewInit(); setup(); glutMainLoop(); }