Mondrian Example Program


The procedure Reshape is called when a window is created, or its size is changed (i.e. the window is reshaped). Both the creation of the window and reshaping are managed by the window system, and involve interaction with the user. The Reshape procedure is passed the width and height of the window.

In this simple program, Reshape is responsible for setting up the default viewport and windowing transformation.

void
Reshape(GLint w, GLint h)
{
[1] glViewport(0, 0, w, h);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

[2] glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}


[1] A viewport is a subset of the window that is used for drawing. No drawing is allowed outside the current viewport. In this program, the viewport is set equal to the entire window.

[2] Next the windowing transformation is specified. The window coordinates define the coordinate system used by the program. The general form of this command is:

The defines a transformation that maps the x value left to the left edge of the window, the x value right to the right edge of the window, and similarly for y and z. In this example, the window coordinates of the lower left corner will be (0,0) and the coordinates of the upper right corner will be (1,1). These coordinates are used by all drawing procedures, and thus they need not know the position or size of the window on the screen.

This program also contains some gl gobbly-gook (glMatrixMode and glLoadIdentity) that can be safely ignored for now. Read about it at your leisure; it will make more sense after we discuss transformations latter in the course.

CS248: Introduction to Computer Graphics, Pat Hanrahan