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 01

Setup

We will use Linux and the following libraries:

Installing sources. In a terminal, do:
  1. Download/extract external libraries and sources
    1. wget http://romain.vergne.free.fr/teaching/IS/data01/TP01.tgz
    2. wget http://romain.vergne.free.fr/teaching/IS/data01/ext.tgz
    3. tar xvzf TP01.tgz && tar xvzf ext.tgz 
  2. If glew is not installed on your machine, go to ext/glew-1.9.0 and compile (make)
  3. If needed, edit the file main.pro to ensure that paths are correct and link to the glew and glm libs
  4. To compile: qmake && make
  5. To run: ./tp01
  6. To edit: use either your prefered text editor or qtcreator

First OpenGL program: a simple animated screensaver

The goal of these exercices is to familiarize yourself with OpenGL windows and primitives. You should obtain something like this:



Exercice 1: Hello World

Open the source file viewer.h/.cpp and observe/understand the structure of the source files:

Exercice 2: OpenGL primitives (OpenGL version < 4)


Basic primitives (points, lines, triangles quads and polygons) in OpenGL can be drawn using the following algorithm:

glBegin(mode);
glColor3f(float,float,float); // set the current color
glVertex3f(float,float,float); // draw a vertex
glVertex3f(float,float,float); // draw another vertex
...
glEnd();

where mode is one of the available OpenGL scheme:
(image taken here)


By default, widget coordinates are in the range [-1,1] in the X and Y directions.

Exercice 3: generating random points

We now would like to distribute and draw some points in the viewer, with randomized positions, colors and sizes.
To that end, we first need to create these points and store them in an array.

The Point structure is defined in viewer.h.

Exercice 4: animating points

We would like the points to move in their respective direction, and making sure that they bounce off the walls of the window.
At each time step, the position of a point should be updated this way:

if
point is outside a wall then
    point.dir = reflected vector between point.dir and wall.normal
endif
point.pos = point.pos + point.dir



Exercice 5: viewport



PREVIOUS: 01 - INRODUCTION
NEXT: 02 - TRANSFORMATIONS