Laboration 1

Procedural images on CPU & GPU

We will here program procedural images, first in C, then in GLSL.

Lab material: We start from a very simple example program. It will render a set of concentric circles. The demo includes code both for generating this image from C and GLSL. The colorization is different fo the two cases, but is otherwise the same.

For 2023, I put the C version aside since the C++ versions work fine and I don’t want to support too many verisons.

2024 version:

https://computer-graphics.se/TNM084/Files/TNM084-labs-2024.zip

Previous version:

2023 version:

https://computer-graphics.se/TNM084/Files/TNM084-labs-2023.zip

This has been tested on Windows, plus Linux and Mac for lab 1, including makefiles. Do I need to make makefiles for lab 3 and 4? At least you have lab 1 to start with. It is not hard to edit it for lab 3 and 4.

Note: Project files for CodeBlocks are included so as long as they work you do not need to create new ones.


For Linux, you may need to install mesa-dev (OpenGL) and libxt-dev (X-Windows).

About the common folder

My code generally uses a code package that I made for other courses, called “common” in the archives above. The package is written in C, but can be used from C++. It includes a shader loader, a texture loader for TGA files, an algebra package, the OBJ loader “LittleObjLoader”, and the window/event interface MicroGlut. The package supports Windows, Linux and MacOSX.

The point with this package is to make it as transparent as possible while still providing necessary features. I believe that transparency is valuable in a course. Few files, keep them small, compile as much as possible directly from source.

I am happy to say that Stefan’s material also had substantial qualities in this direction.

Performing the lab

For each step, save your result so you can demonstrate them. You may simply duplicate the lab folder to lab1.1, lab1.2, lab1.3… Then you should not need to create new projects.

There are some simple questions for each step below. Write down your answers to these before demonstrating.

1. Test the lab environment. Compile and run lab1.c. Change the existing pattern in some simple way. Colors, frequency, position…

How did you change the pattern?

2. Make a substantially different pattern, brick-like pattern or other pattern.

What pattern did you create and how?

3. Use a noise function to produce something (what?)

Functions for Perlin noise, Simplex noise and cellular noise are included.

Noise functions are powerful! Do not stop with something minimal. Just displaying plain noise is not enough. Make something better than what I showed in the lecture! I recommend at least two calls for noise and involving some more operation. Other creative twists are welcome.

How did you use the noise for your new pattern?

4. Move to GLSL! Make something similar to step 2 or 3 so you can compare the implementations.

What was different when implementing it in GLSL?

5. Animated texture in GLSL. Hint: glutRepeatingTimer and glutGet(GLUT_ELAPSED_TIME) can be useful.

How do you create an animation? What additional data was needed?

© Ingemar Ragnemalm 2021