Terrain generation using Perlin Noise and fractals

Why a terrain generation demo? Well, for several reasons:

  • Our image synthesis classes won't start before some weeks and I wanted to give it a try.
  • My portfolio doesn't include a single 3D app since I found my way only recently.
  • I'd like to find an internship in graphics programming, in another country, i.e. in the next two months (see previous point).
  • C'mon, procedural generation is FUN :D

A month ago, I developed a first version of this small application. I used the SFML - after recompiling it - to create the window and an OpenGL context. Then I implemented heightmap generation by "stacking" several layers of Perlin Noise, fractal-style (looks like it's called a "fBm", but I wouldn't venture into defining a term I don't fully grasp yet).

Generated heightmap

The resulting pictures looked nice, so I moved on to the next step: 3D! One vertex per pixel, y-coordinate function of the greyscale value of the heightmap...

Wireframe terrain

Finally, using this tutorial (in French) as a basis, I generated a texture from three input images (grass / rock / snow), blended according to elevation.

Textured terrain

Some filtering now, maybe?

All this took me about one week. I then added some simple keyboard / mouse nav (antigrav-FPS style). The next step was to make the whole thing more usable by adding a GUI. You can read here that the first step, picking a library, wasn't exactly a walk in the park. I settled on gtkmm, which looked very promising...

...until it turned out that there was no way to create an OpenGL context without making the widgets disappear. I tried using the SFML (using this code), and not using it, no way: the context always seems to take hold of the whole window, instead of just its part. After a whole day trying to fix this, I had to resolve to a simple, hacky solution: two windows.

During three weeks, I added functionalities one by one. First, heightmap generation:

Generation tab

Then terrain geometry:

Geometry rendering tab

Then texturing...

Texturing tab

...and lighting.

Sun lighting tab

I won't explain every single button or slider here, that would take a while ;) I'll make the app available, with a readme. I'll also make the sources available even if they're not very interesting (verbose GUI code).

The nuts and bolts of this program are gtkmm for the GUI, SFML for the OpenGL context, two simple shaders, and a VBO (after someone told me displayLists were a bit outdated :D).

I plan to add a proper sky, maybe with some clouds, and a pleasant horizon, either by generating over a larger range or using the hack of this talk (which is: mirroring). Oh, and fog as well. But for now I have cover letters to write and a portfolio to fill :D

EDIT: You can read more about this and find the files here.