Author: Romain Vergne (website
Please cite my name and add a link to my web page if you use this course
Image synthesis and OpenGL: exercices 03
We will use Linux and the following libraries:
Installing sources. In a terminal, do:
- Download the sources at
- If needed, edit the file main.pro to change paths
- To compile: qmake && make
- To run: ./tp03 models/file.off
- To edit: use either your prefered text editor or qtcreator
Towards the OpenGL 4 pipeline
The goal of these exercises is to familiarize yourself with OpenGL
vertex arrays and shaders (that's a lot!). You should obtain something
Exercice 1: real-time coding (with the prof.)
- Shader creation &
- VAO creation & initialization
- Using another attribute (normals)
- CPU transfer
- Sending uniform variables
- CPU transfer
- using the variable inside
Exercice 2: get familiarized with the code
- Have a look at the OpenGL documentation of the following functions:
- glGenBuffers / glDeleteBuffers
- glGenVertexArrays / glDeleteVertexArrays
- glEnableVertexAttribArray / glDisableVertexAttribArray
- glDrawElements / glDrawArrays
Exercice 3: Play with shaders
Each time you change something in the shader file, you can test
directly wihout having to re-execute the program since shaders can be
compiled at runtime.
Simply press the "r" button (see viewer.cpp): it
will call shader->reload and re-compile everything.
Your may also visualize the mesh in wireframe by pressing the "w" key.
Do not forget to read the GLSL
specification for creating and modifying shaders.
- apply some simple transformations (scale/translate/etc) to the mesh
vertices. Observe what happens.
- send a animated uniform variable to the shader (for instance the
scalar _var available in viewer.h)
- animate the transformations
- and / or use the variable to modify the rendering colors
- try different GLSL functions on the output color, for instance
- etc (see the built-in functions in the GLSL documentation)
- Try to modulate your rendering according to any kind of 3D function (how
to obtain a checkerboard effect for instance)?
- What does the function discard do? Try to use it somewhere.