Graphics Reference
In-Depth Information
where attribName is a character string of the name of the variable.
An application can set a per-vertex atribute using one of the functions:
void glVertexAttrib{i}{t}{v}(GLuint index, TYPE val)
The value of i can be 1, 2, 3, or 4, depending on the dimension of the
data to be given to that atribute. The value of t specifies the data type for the
data to be given to the atribute; this can be b (byte), s (short), i (int), f (float),
d (double), ub (unsigned byte), us (unsigned short), or ui (unsigned int). The
suffix v means that the data is in vector form rather than as a list of scalars.
These are consistent with the format of the glVertex* functions.
The parameter index is the particular
symbol table index of the atribute vari-
able you are seting, and the parameter or
parameters val are the value(s) to be writ-
ten to the atribute variable at that index.
All the glVertexAttrib functions are
expected to be used between glBegin and
glEnd , just as the built-in atribute seting
functions are.
The type of the data val is expected
to match the type specified in the function
name. However, since the vertex atributes are always stored in an array of
type vec4 , any byte, short, int, unsigned byte, unsigned short, or unsigned int
will be converted into a standard GLfloat before it is actually stored.
In the short application code fragment below, which uses compatibil-
ity mode for clarity, we assume that the atribute named abArray has been
defined in the vertex shader as, say,
Notice that the glVertexAttrib*
routines do not take a program
handle as one of their arguments.
Since you set the attribute variables
as you do the drawing, it is assumed
that the intended shader program
has already been made active when
glVertexAttrib* is called.
vec3 aMyArray[N]:
and we want to set the values of that atribute for each vertex of a triangle.
The values to be assigned to that atribute for the vertices are the values of
a0 , b0 , and c0 (respectively a1 , b1 , and c1 , or a2 , b2 , and c2 ). The role of the
glVertexAttrib3f( ) function is to set these values for the atribute.
GLint myArrayLoc = glGetAttribLocation( program, “aMyArray” );
if(myArrayLoc < 0 )
fprintf( stderr, “Cannot find Attribute variable
'aMyArray'\n” );
else
{
Search WWH ::




Custom Search