How to do it...

To render an image with reflection based on a cube map, and also render the cube map itself, carry out the following steps:

  1. We'll start by defining a function that will load the six images of the cube map into a single texture target:
GLuint Texture::loadCubeMap(const std::string &baseName, const std::string &extension) {    GLuint texID;    glGenTextures(1, &texID);    glBindTexture(GL_TEXTURE_CUBE_MAP, texID);    const char * suffixes[] = { "posx", "negx", "posy",     "negy", "posz", "negz" };    GLint w, h;    // Load the first one to get width/height    std::string texName = baseName + "_" + suffixes[0] + extension;    GLubyte * data = Texture::loadPixels(texName, w, h, false);    // Allocate immutable storage for the whole cube map texture glTexStorage2D(GL_TEXTURE_CUBE_MAP, ...

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.