Unconstant Conjunction A personal blog

Building Libnoise on OS X

Although it is very old (and unmaintained since 2007), Libnoise is a great library for procedural generation of pseudorandom noise. It provides a wonderfully intuitive way of chaining together various layers and styles of noise that I’ve never seen matched, even in newer implementations. It also supports seeds (which I require), and is largely feature-complete. I’ve used some of the Java and XNA ports in the past, but in the last few days started getting interested in using the original C++ code, partly because I’m wondering if it can be converted into a Python extension.

Since the original Makefile is problematic, someone has gone to the trouble of converting it to cmake, so you can run:

$ git clone git@github.com:eXpl0it3r/libnoise.git
$ cd libnoise
$ cmake .
$ make && make install

To install the static library on your system. This seems to work on OS X Mountain Lion. You can compile a few of the examples (in the examples directory) to try them out. Everyone’s favourite is the worms.cpp demo, but since it uses OpenGL, you’ll have to change

#include <gl/gl.h>
#include <glut.h>

at the top of the file to

#include <OpenGL/gl.h>
#include <GLUT/glut.h>

due to the locations of those libraries on OS X. You can then compile this using (yes, I know it’s a hell of a command):

$ g++ /System/Library/Frameworks/GLUT.framework/GLUT /System/Library/Frameworks/OpenGL.framework/OpenGL -o worms.o worms.cpp -llibnoise

Run it (you may have to chmod +x worms.o first) with:

$ ./worms.o

which opens up a lovely window with some wriggling worms. It should look something like this:

![The Libnoise Worms]({filename}/images/libnoise-worms.png)

Most of the other examples make use of the noiseutils.cpp file, so they can be compiled and run with something like:

$ g++ -o wood.o texturewood.cpp noiseutils.cpp -llibnoise && ./wood.o

The most interesting example is probably to be found in complexplanet.cpp. Although it takes about three full minutes to run on my computer (poor performance has always been the criticism of libnoise), it does produce the kind of image that got me interested in procedural generation to begin with:

![Libnoise Terrain]({filename}/images/libnoise-terrain.png)
comments powered by Disqus