HighMap library (C++)
Loading...
Searching...
No Matches
Quickstart

This guide shows how to generate and export a heightmap using HighMap.

1. Example

The following program generates a 2D elevation grid using Perlin fractal Brownian motion (fBm), remaps its values to the interval $[0, 1]$, and writes the result to a 16-bit PNG file.

#include <iostream>
#include "highmap.hpp"
int main()
{
glm::ivec2 shape = {512, 512};
glm::vec2 res = {4.0f, 4.0f};
int seed = 42;
// Generate elevation data
std::cout << "min: " << z.min() << "\n";
std::cout << "max: " << z.max() << "\n";
// Remap elevation values to [0, 1]
z.remap(0.0f, 1.0f);
// Export to image
hmap::export_image(z, "terrain.png", config);
return 0;
}
Array class, helper to manipulate 2D float array with "(i, j)" indexing.
Definition array.hpp:31
float min(ICommunicator &comm=SingleArrayComm::instance()) const
Return the value of the smallest element in the array.
Definition methods.cpp:321
float max(ICommunicator &comm=SingleArrayComm::instance()) const
Return the value of the greatest element in the array.
Definition methods.cpp:293
int main(int argc, char **argv)
Definition main.cpp:12
Array noise_fbm(NoiseType noise_type, glm::ivec2 shape, glm::vec2 kw, std::uint32_t seed, int octaves=8, float weight=0.7f, float persistence=0.5f, float lacunarity=2.f, const Array *p_ctrl_param=nullptr, const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr, const UvRect &uv_rect=UvRect::unit(), float angle=0.f, float stretch=1.f, float stretch_decay=0.f)
Return an array filled with coherence fbm noise.
Definition noise.cpp:78
@ UINT16
Definition image_writer.hpp:32
@ PERLIN
Perlin.
Definition functions.hpp:69
bool export_image(const Array &array, const std::string &fname, const ImageWriterConfig &config={})
Exports an array using the generic ImageWriter pipeline.
Definition export_image.cpp:23
Definition image_writer.hpp:37
ImageDataType data_type
Definition image_writer.hpp:40

2. CMake Integration

Link against HighMap using CMake:

cmake_minimum_required(VERSION 3.20)
project(my_project CXX)
set(CMAKE_CXX_STANDARD 20)
find_package(HighMap REQUIRED)
add_executable(my_project main.cpp)
target_link_libraries(my_project PRIVATE HighMap::HighMap)

3. Basic Operations

Common operations on an Array:

  • Smoothing:
    z = hmap::smooth(z, 3);
    Path smooth(const Path &path, int navg=1, float averaging_intensity=1.f, float inertia=0.f)
    Applies a smoothing operation to the path points using a moving average filter.
    Definition path_functions.cpp:732
  • Clamping:
    z.clamp(0.0f, 1.0f);
  • Blending:
    hmap::Array overlay = hmap::noise_fbm(hmap::NoiseType::PERLIN, shape, {8.f, 8.f}, 101);
    z = hmap::blend_max(z, overlay * 0.5f);

4. Next Steps