Last update: 2 September 2015

Tutorial 5: SkyBox

This tutorial loads and display a skyBox using OpenGL cube map texture. The cube map texture is composed of six 2D textures, each 2D texture  is mapped to one of the six faces of the cube map. To allocate the 6 textures we call glTexImage2D 6 times for each face, the target parameter in glTexImage2D will tells the driver for which of the 6 faces we want to allocate storage. For example to upload the data from the central memory to the cube map texture on positive X axis:

glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_X,
                          mip_level,
                          internal_format,
                          width,
                          height,
                          border,
                          host_data_format,
                          host_data_type,
                          host_data_xp) 

where the first parameter tells OpenGL that we want to upload data to the positive x axis of the cube map. the last two parameters specifiies the type and memory adress of the host data we want to upload to the GPU.

The CCacheResourceManager located in the framework loads and return a ready to use cube map texture.   Please note that the six faces of the cube map texture should be named like this

( base name + underscore + direction vector ):

  • skyboxName_xn.jpg (or png)
  • skyboxName_xp.jpg
  • skyboxName_yn.jpg
  • skyboxName_yp.jpg
  • skyboxName_zn.jpg
  • skyboxName_zp.jpg
 To load the skybox you give only the base name to the resource manager :

CTextureCubeMap *textureCubeMap = crm.LoadTextureCube("skyboxName.jpg");

The  functuon LoadTextureCube loads and uploads each image to the corresponding face of the cube map texture. the function returns a cube map texture object that can be used and sampled by the pixel shader.