/* nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
PROGRAMMER: Roger W. Ehrich
DATE: 1 September, 1998
REVISION: 1
FOR: Class demonstration
PURPOSE: Here we define a master object using a
display list and create several instances
uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu */
#include
void display (void) {
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.0, 0.0);
glCallList (1);
glTranslated (.2, .2, 0.0);
glColor3f (0.0, 1.0, 0.0);
glCallList (1);
glTranslated (-0.1, .15, 0.0);
glColor3f (0.0, 0.0, 1.0);
glCallList (1);
glFlush ();
}
void reshape(GLint w,GLint h) {
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)w/250.,0.0,(GLdouble)h/250.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void init (void) {
glClearColor (0.0, 0.0, 0.0, 1.0);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
void main(int argc, char** argv) {
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Master Demonstration");
init ();
glNewList (1, GL_COMPILE);
glBegin (GL_POLYGON);
glVertex3d (0.25, 0.1, 0.0);
glVertex3d (0.75, 0.1, 0.0);
glVertex3d (0.75, 0.6, 0.0);
glVertex3d (0.25, 0.6, 0.0);
glEnd ();
glEndList ();
glutDisplayFunc (display);
glutReshapeFunc (reshape);
glutMainLoop ();
}
When the program runs, the following is produced:

When the window is reshaped, the reshape callback prevents the aspect ratio of the squares from being changed.

There is an error in the display callback. To see this, run the program, cover the window, and uncover it again. How should this be fixed? If you remove the reshape callback, you see the result of the error in the display callback as well as a change in aspect ratio. Just how does the reshape callback fix this change in aspect ratio?