12/21

3.2. Uniform parameters and animation

The following code send a rotation matrix as uniform to model a rotating triangle.

[ code, main.cpp ]

  • Compile and execute this code and make sure you can observe the rotation of the triangle.

triangle

Exercise

  • Change the speed of the rotation in modifying the computation of the variable t.

  • Create a new Uniform variable color used to defined the color of fragments in the fragment shader.


Consider the following position data

const std::vector<GLfloat> position = {
    -0.5f, -0.5f, 0.0f,
     0.5f, -0.5f, 0.0f,
     0.0f,  0.5f, 0.0f,


     0.2f,  0.2f, 0.0f,
     0.8f,  0.2f, 0.0f,
     0.8f,  0.8f, 0.0f
};

We suppose that the first three positions correspond to a red triangle, and the last three correspond to a green triangle.

  • Using your previous uniform variable color, implement the display of these two triangles (both will follow the same rotation).

two triangles

Hints

The display procedure can be the following

  1. Send Rotation matrix as uniform

  2. Send the red color as uniform

  3. Display the first three vertices

  4. Send the green color as uniform

  5. Display the next three vertices