Page 64 - Computer Graphics Handout
P. 64
by glutInit Window Size. If they differ, as depicted in Figure 2.36, objects are distorted on the screen. This distortion is a consequence
of our default mode of operation, in which the entire clipping rectangle is mapped to the display window.
The only way that we can map the entire contents of the clipping rectangle to the entire display window is to distort the contents
of the former to fit inside the latter. We can avoid this distortion if we ensure that the clipping rectangle and display window
have the same aspect ratio. Another, more flexible, method is to use the concept of a viewport. A viewport is a rectangular area of
the display window. By default, it is the entire window, but it can be set to any smaller size in pixels via the function
void glViewport(GLint x, GLint y, GLsizei w, GLsizei h);
where (x,y) is the lower-left corner of the viewport (measured relative to the lowerleft corner of the window) and w and h give the
width and height, respectively. The types are all integers that allow us to specify positions and distances in pixels. Primitives are
displayed in the viewport, as shown in Figure 2.37. For a given window, we can adjust the height and width of the viewport to match
the aspect ratio of the clipping rectangle, thus preventing any object distortion in the image. The viewport is part of the state. If we
change the viewport between rendering objects or rerender the same objects with the viewport changed, we achieve the effect
of multiple viewports with different images in different parts of the window.We will see further uses of the viewport in Chapter 3,
where we consider interactive changes in the size and shape of the window.
2.7.3 The main, display, and init Functions
In principle, we should be able to combine the simple initialization code with our code from Section 2.1 to form a complete OpenGL
program that generates the Sierpinski gasket. Unfortunately, life in a modern system is not that simple.
There are two problems: One is generic to all graphics systems; the second has more to do with problems of interacting with the
underlying windowing system. Our basic mechanism for display will be to form a data structure that contains all the geometry and
attributes we need to specify a primitive and how we would like it displayed.We then send this structure to the shaders that will
process our data and display the results. Once the application has sent the data to the shaders, it is free to do other tasks. In an
interactive application, we would continue to generate more primitives.
64

