OpenGL Shading Language Tutorials

Using Uniform Variables in Fragment Shaders


Using uniform variables in fragment shaders is exactly the same like in vertex shaders:

A simple OGLSL Fragment Shader

uniform vec3 myColor;
void main (void)
{
   gl_FragColor = vec4(myColor, 1.0);
}

This fragment program receives a color (3 component float vector) from the C++ program and sets the fragment color to this value.

 

 

C++

myShader->sendUniform3f("myColor", 0.7, 0.3, 0.1);

Now we can communicate to the Vertex and Fragment shader.

 


Go to Tutorial 4

 


Author: Martin Christen, christen@clockworkcoders.com
(source code is included in Tutorial Version 0.1 and higher)

 

 

© 2003 by Martin Christen. All Rights Reserved.
christen@clockworkcoders.com