13.07.2015 Views

Mali GPU User Interface Engine Application Development Guide

Mali GPU User Interface Engine Application Development Guide

Mali GPU User Interface Engine Application Development Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Tutorial on Drawing 3D Shapes4.3 Texturing the cube facesThis tutorial combines:• drawing a 3D cube• texturing each 2D face of the cube• reacting to keyboard input to rotate the cube or move the camera.1. Locate the shader example 03 - Texturing and open the texturing.cpp file2. Example 4-8 shows the standard initialization code and loading the shaders:Example 4-8 Initalization for the textured cube...#include using namespace MDE;static const float PI = 3.14159265;inline vec3 calculateCamPos(float radius, float angle){float angleRad = angle / 180 * PI;return vec3(radius * cos(angleRad), 2.0f, radius * sin(angleRad));}int main(int argc, char * argv[]){try{Managed system = create_system_backend();Managed context = system->createContext(320, 240);#ifdef MDE_OS_PC_LINUXManaged keyboard = system->createKeyboard(context);#elseManaged keyboard = system->createKeyboard();#endifManaged filesystem = system->createFileSystem(".");...Proxy proxy(filesystem, context);Program *texturingProgram =proxy.getProgram("shaders/texturing.vert;shaders/texturing.frag");Texture2D *texture = proxy.getTexture2D("data/rock_t.png");texture->setFilterMode(GL_NEAREST, GL_NEAREST);3. Example 4-9 shows how to set the locations for the cube vertices and the correspondinglocations in the texture bitmap.Example 4-9 vertexData for the textured cube...GLfloat vertexData[] = {// FRONT-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, //xyz for vertices, uv for texture0.5f, -0.5f, 0.5f, 1.0f, 0.0f,-0.5f, 0.5f, 0.5f, 0.0f, 1.0f,0.5f, 0.5f, 0.5f, 1.0f, 1.0f,// BACK-0.5f, -0.5f, -0.5f, 0.0f, 0.0f,-0.5f, 0.5f, -0.5f, 1.0f, 0.0f,0.5f, -0.5f, -0.5f, 0.0f, 1.0f,ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 4-8ID070710Non-Confidential - Draft - Beta

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!