Uniform variables are used to communicate with your vertex or fragment shader from "outside". In your shader you use the uniform qualifier to declare the variable:
Uniform variables are read-only and have the same value among all processed vertices. You can only change them within your C++ program.
In this example the vertex shader scales every incoming vertex with a value spcified in a uniform variable. In the fragment shader a uniform vector value is used as the output color.
Changing the Uniform Value in C++
Access to uniform variables is available after linking the program. With glGetUniformLocation you can retrieve the location of the uniform variable within the specified program object. Once you have that location you can set the value. If the variable is not found, -1 is returned. With glUniform you can set the value of the uniform variable.
The uniform location remains valid until you link the program again, so there is no need to call glGetUniformLocation every frame.
In this example project the above example shaders are used and the vertex position and color value is changed with a timer function.
GLSL_Uniform.zip (Visual Studio 8 Project)