//A very simple opengl/GLUT program #include #include #include //global variables - necessary evil when using GLUT //global width and height int GW; int GH; //current mouse position in pixel coordinate int x; int y; //a structure to store 2D points - this could also be a class typedef struct vector2 { float x; float y; } vector2; //an array to store ten 2D points vector2 ten_pts[10]; //keep track of the number of points stored thus far int num_pts; //keep track of which drawing mode we are in points or square //mode ==0 means draw square otherwise draw points int mode; //helper drawing routines void draw_square() { glBegin(GL_POLYGON); glColor3f(1.0, 0.0, 0.0); glVertex2f(-0.5,-0.5); glColor3f(0.0, 1.0, 0.0); glVertex2f(-0.5,0.5); glColor3f(0.0, 0.0, 1.0); glVertex2f(0.5,0.5); glColor3f(0.0, 0.0, 0.0); glVertex2f(0.5,-0.5); glEnd(); } void draw_pts() { glPointSize(2.0); glBegin(GL_POINTS); glColor3f(0.5, 0.2, 0.8); for (int i=0; i