Getting ready

First, prepare the six images of the cube map. In this example, the images will have the following naming convention. There is a base name (stored in the baseFileName variable) followed by an underscore, followed by one of the six possible suffixes (posx, negx, posy, negy, posz, or negz), followed by the file extension. The suffixes posx, posy, and so on, indicate the axis that goes through the center of the face (positive x, positive y, and so on).

Make sure that they are all square images (preferably with dimensions that are a power of two), and that they are all the same size.

Set up your OpenGL program to provide the vertex position in attribute location 0, and the vertex normal in attribute location 1.

This vertex shader ...

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.