How it works...

The GLM library provides 2D, 3D, and 4D coherent noise via the glm::perlin function. It returns a float roughly between -1 and 1. We start by allocating a buffer named data to hold the generated noise values.

Next, we loop over each texel and compute the x and y coordinates (normalized). Then, we loop over octaves. Here, we compute the sum of the previous equation, storing the first term in the first component, the first two terms in the second, and so on. The value is scaled into the range from 0 to 1, then multiplied by 255 and cast to a byte.

The next few lines of code should be familiar. Texture memory is allocated with glTexStorage2D and the data is loaded into GPU memory using glTexSubImage2D.

Finally, the array named ...

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.