Page 59 - Computer Graphics Handout
P. 59
the window system is also more complex than with RGB color. Consequently, for the most part, we will assume that we are using
RGB color.
The major exception is when we consider a technique called pseudocoloring, where we start with a monochromatic image. For
example, we might have scalar values of a physical entity such as temperature that we wish to display in color. We can create a
mapping of these values to red, green, and blue that are identical to the color-lookup tables used for indexed color.
2.5.3 Setting of Color Attributes
For our simple example program, we use RGB color. We have three attributes to set.The first is the clear color, which is set to white
by the following function call:
glClearColor(1.0, 1.0, 1.0, 1.0);
Note this function uses RGBA color. The color we use to render points is set in the shaders. We can set an RGB color in the application
such as
typedef vec3 color3;
color3 point_color = color3(1.0, 0.0, 0.0);
or as an RGBA color as
typedef vec4 color4;
color4 point_color = color4(1.0, 0.0, 0.0, 1.0);
and send this color to the vertex shader. We could also set the color totally in the shader. We will see a few options later in this
chapter. We can set the size of our rendered points to be 2 pixels wide by using the following OpenGL function:
glPointSize(2.0);
Note that attributes, such as the point size and line width, are specified in terms of the pixel size.Hence, if two displays have
11
different-sized pixels (due to their particular screen dimensions and resolutions), then the rendered images may appear slightly
different. Certain graphics APIs, in an attempt to ensure that identical displays will be produced on all systems with the same user
program, specify all attributes in a device independent manner. Unfortunately, ensuring that two systems produce the same display
has proved to be a difficult implementation problem. OpenGL has chosen a more practical balance between desired behavior and
realistic constraints.
2.6 VIEWING
We can now put a variety of graphical information into our world, and we can describe how we would like these objects to appear,
but we do not yet have a method for specifying exactly which of these objects should appear on the screen. Just as what we record
in a photograph depends on where we point the camera and what lens we use, we have to make similar viewing decisions in our
program. A fundamental concept that emerges from the synthetic-camera model that we introduced in Chapter 1 is that the
specification of the objects in our scene is completely independent of our specification of the camera. Once we have specified both
the scene and the camera, we can compose an image. The camera forms an image by exposing the film, whereas the computer
system forms an image by carrying out a sequence of operations in its pipeline. The application program needs to worry only about
the specification of the parameters for the objects and the camera, just as the casual photographer is concerned about the resulting
picture, not about how the shutter works or the details of the photochemical interaction of film with light.
There are default viewing conditions in computer image formation that are similar to the settings on a basic camera with a fixed
lens. However, a camera that has a fixed lens and sits in a fixed location forces us to distort our world to take a picture. We can
create pictures of elephants only if we place the animals sufficiently far from the camera, or we can photograph ants only if we put
the insects relatively close to the lens. We prefer to have the flexibility to change the lens to make it easier to form an image of a
collection of objects. The same is true when we use our graphics system.
2.6.1 The Orthographic View
The simplest and OpenGL’s default view is the orthographic projection. We discuss this projection and others in detail in Chapter 4,
but we introduce the orthographic projection here so that you can get started writing three-dimensional programs. Mathematically,
11
Note that point size is one of the few state variables that can be set using an OpenGL function in
the latest versions.
59

