#include #include #include using namespace std; const GLfloat Pi=3.1415926536; const GLfloat sqrt2=1.4142135624; GLint transform = 0; void myInit() { glClearColor(1.0,1.0,1.0,0.0); glColor3f( 0 , 0 , 0 ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D( -200 , 200 , -200 , 200 ); glMatrixMode(GL_MODELVIEW); } void drawSquare(GLint length) { glColor3f(1,0,0); glBegin(GL_POLYGON); glVertex2f(0,0); glVertex2f(length,0); glVertex2f(length,length); glVertex2f(0,length); glEnd(); } void display() { glClear(GL_COLOR_BUFFER_BIT); if (transform == 1) { } drawSquare(50); // this code renders a set of axes anchored at the origin glPushMatrix(); glLoadIdentity(); glColor3f(0,0,0); glBegin(GL_LINES); glVertex2f(0,0); glVertex2f(0,100); glVertex2f(0,0); glVertex2f(100,0); glEnd(); // this code renders a several points used in the lab glPointSize(5.0); glBegin(GL_POINTS); glColor3f(1,0,0); glVertex2f(50,0); glColor3f(0,1,0); glVertex2f(35,35); glColor3f(0,0,1); glVertex2f(70,35); glColor3f(1,0,0); glVertex2f(-50,0); glEnd(); glPopMatrix(); glFlush(); } //clicking on the left mouse button will toggle the transform flag and post a redisplay void mouse (GLint btn, GLint state, GLint x, GLint y) { if (btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN) { transform=1; glutPostRedisplay(); } } // set up the keyboard callback void keyboard (unsigned char key , int x, int y) { if ( key=='q' || key=='Q' ) { exit( 0 ); } } int main( int argc , char **argv ) { glutInit(&argc,argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(400,400); glutInitWindowPosition(0,0); glutCreateWindow("Transforms"); myInit(); glutDisplayFunc(display); glutMouseFunc(mouse); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }