Silicon Graphics

[Prev] [TOC] [Next]



(-) OpenGL Programming Guide
(-) Chapter 3Viewing
(-) Viewport Transformation

Defining the Viewport

The window manager, not OpenGL, is responsible for opening a window on the screen. However, by default the viewport is set to the entire pixel rectangle of the window that's opened. You use the glViewport() command to choose a smaller drawing region; for example, you can subdivide the window to create a split-screen effect for multiple views in the same window. void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);

Defines a pixel rectangle in the window into which the final image is mapped. The (x, y) parameter specifies the lower left corner of the viewport, and width and height are the size of the viewport rectangle. By default, the initial viewport values are (0, 0, winWidth, winHeight), where winWidth and winHeight are the size of the window.

The aspect ratio of a viewport should generally equal the aspect ratio of the viewing volume. If the two ratios are different, the projected image will be distorted as it's mapped to the viewport, as shown in Figure 3-15 . Note that subsequent changes to the size of the window don't explicitly affect the viewport. Your application should detect window resize events and modify the viewport appropriately.

[IMAGE]

Figure 3-15 : Mapping the Viewing Volume to the Viewport


For example, this sequence maps a square image onto a square viewport:

gluPerspective(myFovy, 1.0, myNear, myFar); 
glViewport(0, 0, 400, 400);

However, the following sequence projects a nonequilateral rectangular image onto a square viewport. The image appears compressed along the x-axis, as shown in Figure 3-15 .

gluPerspective(myFovy, 2.0, myNear, myFar); 
glViewport (0, 0, 400, 400);

To avoid the distortion, this line could be used:

glViewport(0, 0, 400, 200);

Try This

Try This


[Prev] [TOC] [Next]

OpenGL Programming Guide


Maintained by Maintainer: Send e-mail to .htm">name@address.