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:
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)
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.