Graphics Reference
In-Depth Information
to manipulate the contents of those matri-
ces yourself, then you can accomplish this
using matrix uniform variables.
If you have defined a struct as a uni-
form variable, you cannot set the entire
struct at once; you must use the functions
above to set each field individually.
As an example, suppose you wanted
to pass a light location into your shaders.
The following very short code fragment, to
be used in your application, wants to store
a value in your shader's vec3 uniform vari-
able named uLightPos .
The glGetUniformLocation function
lets you find the location of the uniform
variable in the shader program's symbol
table. The glUniform3fv function lets you set that uniform variable. Note also
how location is checked to ensure that the variable is actually found.
Notice that none of these glUniform*
routines take a program handle as
one of its arguments. Those routines
set uniform variables in the currently
active shader program. So be sure
that you call glUseProgram( ) on
the correct program before setting
that program's variables.
However, there is another set
of GLSL API routines that let you
specify the program. They look like
this:
glProgramUniform*( program,
loc, count, value(s) );
float LightPos[3] = { 0., 100., 0. }; // values to store
GLint lightPosLoc = glGetUniformLocation( program,
“uLightPos” );
// where in the shader symbol table to store them
if( lightPosLoc < 0 )
fprintf(stderr, “Uniform variable 'uLightPos' not found\n”);
. . .
glUseProgram( program );
if( lightPosLoc >= 0 )
glUniform3fv( lightPosLoc, 3, lightPos );
A Convenient Way to Transition to the Newer Versions of GLSL
The GLSL specification has been in transition. Many (most) of the built-in
GLSL variables have been deprecated in favor of defining and using your
own variable names. Although it is not clear if the GLSL deprecated features
will completely go away, it is clear that they might. We believe that graphics
programmers should start transitioning to the new way of doing things. This
is further supported by that fact that OpenGL ES 2.0 requires the transition
Search WWH ::




Custom Search