Graphics Reference
In-Depth Information
glVertexAttrib2f( UVloc, u2, v2 );
glVertex3f( x2, y2, z2 );
glEnd( );
}
A visualization per-vertex atribute example could display pressure data
on a surface. The usual way this would be presented with the fixed-function
OpenGL would be to use the pressure to define the color at each vertex in the
surface, and then—assuming a continuous pressure function on the surface—
to send the surface's graphics primitives into the rendering stages, to be drawn
with smooth shading. However, we could also deine pressure to be an atri-
bute variable with each vertex, and use that directly for drawing the surface,
giving us more options on using color to present the pressure data.
The steps in doing this are as follows:
Deine the atribute variable in the application and set the variable to its
appropriate value for each vertex as you define the vertex geometry.
Pick up the value of the atribute variable in the vertex shader and write
it to a varying variable so it can be interpolated smoothly across each
graphics primitive.
Use the varying variable's value to determine the color to be used in fill-
ing pixels.
This would let us add pressure contour lines, or would let us color differ-
ent pressure regimes in distinct colors, or create other displays as needed. This
idea will be explored more fully in Chapter 15.
Attribute Variables in Compatibility Mode
If you are working in compatibility mode, you may have a number of built-in
atribute variables for a vertex shader to use directly or to pass along to other
shaders. Each of the standard OpenGL functions that define a vertex (those
you can call within a glBegin - glEnd pair) deines a built-in atribute variable
that can be used by a vertex shader. These include
attribute vec4 gl_Color;
attribute vec3 gl_Normal;
attribute vec4 gl_Vertex;
attribute vec4 gl_MultiTexCoord0;
These variables correspond to the standard OpenGL vertex functions, as
shown in Table 14.2.
Search WWH ::




Custom Search