How it works...

In step 2, the ColorImg uniform variable is the output image. It is defined to be located at the image texture unit 0 (via the binding layout option). Also note that the format is rgb8, which must be the same as what is used in the glTexStorage2D call when creating the texture.

MAX_ITERATIONS is the maximum number of iterations of the complex polynomial mentioned earlier. CompWindow is the region of complex space with which we are working on. The first two components CompWindow.xy are the real and imaginary parts of the lower-left corner of the window, and CompWindow.zw is the upper right corner. Width and Height define the size of the texture image.

The mandelbrot function (step 3) takes a value for c as the parameter, and ...

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.