/* 1. Compile and run this code. 2. Reshape your window. What happens? Does the entire polygon get rendered? Is it still square? 3. Create (and enable the use of) a reshape function which: - adjusts the pixel rectangle for drawing to be the entire new window, this is your glViewport call. - adjusts the clipping volume so the lower-left corner is 0,0, and the upper right is w,h , this is your call to gluOrtho2D . So, your new reshape should preserve the aspect ratio of the polygon (it stays square), but the polygon might might get clipped if the new window is smaller than 200 pixels wide and 200 pixels tall. 4. Finally, modify the projection (what you do with gluOrtho2D) in your reshape function so it preserves the aspect ratio of the original polygon, and renders the entire polygon to the new window. 5. Update your code from #4 above so that the polygon is always centered in the resized window. */ #include #include using namespace std; #define WINDOW 400 void myInit() { glClearColor(1.0,1.0,1.0,0.0); glColor3f(0.0,0.0,0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0,400,0,400); glMatrixMode(GL_MODELVIEW); } void reshape (GLint w, GLint h) { } void display() { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glVertex2f(100,100); glVertex2f(300,100); glVertex2f(300,300); glVertex2f(100,300); glEnd(); glFlush(); } int main (int argc , char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(WINDOW,WINDOW); glutInitWindowPosition(100.0,100.0); glutCreateWindow("Reshape"); glutDisplayFunc(display); // glutReshapeFunc(reshape); myInit(); glutMainLoop(); return 0; }