#include #include #include int width = 400; int height = 400; void drawbox() { glBegin(GL_QUADS); glVertex2f(0, 0); glVertex2f(1, 0); glVertex2f(1, 1); glVertex2f(0, 1); glEnd(); } void draw () { glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Perform Transformation glPushMatrix(); glTranslatef(1, 1, 0); glRotatef(-45, 0, 0, 1); glScalef(2, 2, 0); // Draw Box glColor3f(1, 0, 0); drawbox(); glPopMatrix(); // Perform Transformation (reversed) glPushMatrix(); glScalef(2, 2, 0); glRotatef(-45, 0, 0, 1); glTranslatef(1, 1, 0); // Draw Box glColor3f(0, 1, 0); drawbox(); glPopMatrix(); // Perform Transformation (proper rotation and scale) glPushMatrix(); glScalef(2, 2, 0); glRotatef(-45, 0, 0, 1); glTranslatef(-0.5, -0.5, 0); // Draw Box glColor3f(0, 0, 1); drawbox(); glPopMatrix(); // Draw Origin glPointSize(5.0); glBegin(GL_POINTS); glColor3f(1, 1, 1); glVertex2f(0, 0); glEnd(); glFlush(); } int main (int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowSize(width, height); glutCreateWindow("Basic Transformation"); glutDisplayFunc(draw); glMatrixMode(GL_PROJECTION); glOrtho(-4.0, 4.0, -4.0, 4.0, -1000, 1000); glutMainLoop(); return 0; }