Graphics Reference
In-Depth Information
glBegin( GL_TRIANGLES );
glVertexAttrib3f( myArrayLoc, a0, b0, c0 );
glVertex3f( x0, y0, z0 );
glVertexAttrib3f( myArrayLoc, a1, b1, c1 );
glVertex3f( x1, y1, z1 );
glVertexAttrib3f( myArrayLoc, a2, b2, c2 );
glVertex3f( x2, y2, z2 );
glEnd( );
}
A very simple visualization per-vertex atribute example would display
pressure data on a surface. The usual way this would be programmed 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 func-
tion on the surface—to send the surface's graphics primitives into the render-
ing stages, to be drawn with smooth shading color interpolation. However, we
could also deine pressure to be an atribute variable with each vertex, and use
that directly for drawing the surface, giving us more options in using color to
present the pressure data.
Attribute Variables in Compatibility Mode
In compatibility mode, GLSL defines a number of built-in attribute 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) defines a built-in attribute variable that can be used by a vertex shader. Each
time one of these functions is invoked, the corresponding attribute variable's value is
updated. These variables are defined fully in Chapter 5 on the GLSL language, and are
shown in Table 3.1.
attribute vec4 gl_Color;;
attribute vec3 gl_Normal;
attribute vec4 gl_Vertex;
attribute vec4 gl_MultiTexCoord0;
Standard OpenGL Function
Built-in Atribute Variable
Our Name
glVertex*(...)
gl_Vertex
aVertex
glColor*(...)
gl_Color
aColor
glNormal*(...)
gl_Normal
aNormal
glMultiTexCoord*(i, ...)
gl_MultiTexCoordi, i=1..N
aTexCoord0
Table 3.1. Atribute variables deined by compatibility-mode OpenGL vertex functions.
Search WWH ::




Custom Search