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.

Lab shell:

http://computer-graphics.se/TNM084/Files/lab1.zip

Slightly updated (nicer for Linux):

http://computer-graphics.se/TNM084/Files/lab1-mod.zip

The “common” folder with utility code:

http://computer-graphics.se/TNM084/Files/common-windows.zip

Makefile for Mac (tested on 10.14)

Makefile for Linux (tested on Ubuntu Budgie)

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” 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.

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