Graphics Reference
In-Depth Information
Now suppose we want to use a rainbow scale, so that the left end is
blue, the right end is red, and the locations in between are colored as in Fig-
ure 15.24.
But suppose we take the naïve approach and draw the bar as a single
quadrilateral with blue at the left end and red at the right end, drawing the bar
using OpenGL smooth shading. Figure 15.25 shows what we would get. You
see that you have no control over what lies between the two ends.
Because OpenGL interpolates each color component separately, it has
no way to get the rainbow scale. In interpolating the left ( r , g , b ) to the right
( r , g , b ), the red component would go from 0 to 1, the green component would
always be 0, and the blue component would go from 1 to 0. But if, instead, the
temperatures at the corners were given as variables to be interpolated, then
the interpolated temperatures throughout the quadrilateral could be mapped
to colors using your transfer function in the fragment shader, exactly as you
wanted.
Passing in Data Values with Your Geometry
So far we have dealt with data values that are just sort of “there” and have
created artificial underlying geometry in order to view them. But there are a
multitude of visualization problems in which data is
atached to a very speciic underlying geometry. How
do we end up with the right colors being displayed
on the geometry as easily and as efficiently as pos-
sible? How would we know if the colors chosen for
Figure 15.26 are right?
The first approach is the non-shader way of
doing things with fixed-function OpenGL. It amounts
to doing the color mapping in the CPU part of the
application and using the rasterizer to interpolate the
colors. This is probably clearest if we use compatibil-
ity mode to describe the geometry:
glBegin( GL_QUADS );
< convert s0 to r0,g0,b0,a0 >
glColor4f( r0, g0, b0, a0 );
glVertex3f( x0, y0, z0 );
. . .
glEnd( );
Figure 15.26. Example of assigning a sca-
lar value and its corresponding color, per
vertex. being drawn. (Image courtesy of
Chris Janik.)
Search WWH ::




Custom Search