Tutorial on Drawing 3D Shapes4.6 Cube mappingThis tutorial combines:• using a geometry asset, in this example it is a teapot• using mirror texturing• creating a skybox that gives the illusion of a complex background.Open the 8-Cube Mapping shader example:1. Example 4-40 shows the standard initialization code. The textureCube provides theenvironment that contains the shape:Example 4-40 Initialization for the cube mapping application...#include using namespace MDE;static const float PI = 3.14159265;/*** Function that calculates the camera position given an angle and a radius. This function* enables the camera to rotate around the scene object.*/inline vec3 calculateCamPos(float radius, float angle){float angleRad = angle / 180 * PI;return vec3(radius * cos(angleRad), 0.0f, radius * sin(angleRad));}/*** Function that loads 6 textures from the hard drive and creates a cubemap from them.*/Managed loadCubeMap(Managed context, Proxy &proxy){Managed textureCube = context->createTextureCube();MDE::Bitmap2DAsset* tmpTex = NULL;tmpTex = proxy.getBitmap2DAsset("data/3.png");textureCube->buildMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0,tmpTex->getWidth(), tmpTex->getHeight(),tmpTex->getPixelFormat(), tmpTex->getPixels() );tmpTex = proxy.getBitmap2DAsset("data/opp.png");textureCube->buildMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0,tmpTex->getWidth(), tmpTex->getHeight(),tmpTex->getPixelFormat(), tmpTex->getPixels() );tmpTex = proxy.getBitmap2DAsset("data/4.png");textureCube->buildMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0,tmpTex->getWidth(), tmpTex->getHeight(),tmpTex->getPixelFormat(), tmpTex->getPixels() );tmpTex = proxy.getBitmap2DAsset("data/1.png");textureCube->buildMipmaps(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0,tmpTex->getWidth(), tmpTex->getHeight(),tmpTex->getPixelFormat(), tmpTex->getPixels() );tmpTex = proxy.getBitmap2DAsset("data/ned.png");textureCube->buildMipmaps(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0,ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 4-32ID070710Non-Confidential - Draft - Beta
Tutorial on Drawing 3D Shapes}...tmpTex->getWidth(), tmpTex->getHeight(),tmpTex->getPixelFormat(), tmpTex->getPixels() );tmpTex = proxy.getBitmap2DAsset("data/2.png");textureCube->buildMipmaps(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0,tmpTex->getWidth(), tmpTex->getHeight(),tmpTex->getPixelFormat(), tmpTex->getPixels() );return textureCube;The cube map uses the following bitmaps:1.pgn This is the image for wall one, see Figure 4-15:2.pgn This is the image for wall two, see Figure 4-16:Figure 4-15 Environment bitmap 1.png3.pgn This is the image for wall three, see Figure 4-17:Figure 4-16 Environment bitmap 2.pngFigure 4-17 Environment bitmap 3.png4.pgn This is the image for wall four, see Figure 4-18 on page 4-34:ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 4-33ID070710Non-Confidential - Draft - Beta