Search code examples
c++eclipseterrainperlin-noise

Using Libnoise to generate a heightmap


I am attempting to implement the libnoise libraries and generate a heightmap which I can then import into L3DT to render a basic 3D terrain using the Perlin noise algorithm. This is my final year project as an undergrad in computer science. The topic is essentially Procedural Content Generation focusing on Terrain Generation.

I've set up my Eclipse CDT properly and linked all the necessary header files and libraries. The program is exactly as described on the libnoise tutorial series, in particular the third tutorial which I shall link here: http://libnoise.sourceforge.net/tutorials/tutorial3.html

Everything seems to be working fine, the build is successful, the program runs to completion, but no matter what I do the output Bitmap file, "output.bmp" is not rendered in the directory of the executable.

What am I missing here? Is the output file placed somewhere else in a default directory?

Here is the code for further clarification:

  /*
  * Noise.cpp
  *
  *  Created on: 23-Feb-2015
  *    
  */

  #include <iostream>
  #include <stdio.h>
  #include <noise.h>
  #include <noiseutils.h>

  using namespace noise; // Sets reference for usage of the the noise class objects
  using namespace std;
  void main()
  {
        // CREATION OF THE NOISE MAP

        module::Perlin Module; // Instantiates the Perlin class object to be used as the source for the noise generation.
        utils::NoiseMap heightMap; // Creation of the 2D empty noise map.
        utils::NoiseMapBuilderPlane heightMapBuilder; // Used to fill the noise map with the noise values taken from an (x,y) plane.

        heightMapBuilder.SetSourceModule (Module); // Sets the Perlin module as the source for noise generation.
        heightMapBuilder.SetDestNoiseMap (heightMap); // Sets the empty noise map as the target for the output of the planar noise map builder.

        heightMapBuilder.SetDestSize(256,256); // Sets the size of the output noise map.

        heightMapBuilder.SetBounds (2.0, 6.0, 1.0, 5.0); // Defines the vertices of the bounding rectangle from which the noise values are produced. lower x, upper x, lower y, upper y.

        heightMapBuilder.Build (); // Builds the noise map.

// RENDERING THE TERRAIN HEIGHT MAP

        utils::RendererImage renderer;
        utils::Image image;
        renderer.SetSourceNoiseMap(heightMap);
        renderer.SetDestImage(image);
        renderer.Render();
// WRITING THE HEIGHT MAP IMAGE TO AN OUTPUT FILE

        utils::WriterBMP writer;
        writer.SetSourceImage(image);
        writer.SetDestFilename("output.bmp");

        system("pause");
}

Solution

  • In the following lines of code you setup a utils::WriterBMP instance with the image data and a file name

        utils::WriterBMP writer;
        writer.SetSourceImage(image);
        writer.SetDestFilename("output.bmp");
    

    But you never actually call a function of writer to write the image data. I can't actually find that class or what the function name should be from their documentation. But I'm pretty sure you can figure this out easily.