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 Constructing Custom ShadersExample 6-24 Transformations in the draw loop...// execute the draw loopglEnable(GL_DEPTH_TEST);do{// use the keyboard to change the imageif (keyboard->getSpecialKeyState(Keyboard::KEY_SPACE)){// Rotate cameraif (keyboard->getSpecialKeyState(Keyboard::KEY_LEFT)){// Move camera (by rotating it) to create a new camera anglecamPos = calculateCamPos(4.0f, ++cameraAngle);// create a transformation matrix based on the new relationship// camera has changed, so view must be updatedview = mat4::lookAt(camPos, camTarget, upVector);}...}else{// Rotate objectif (keyboard->getSpecialKeyState(Keyboard::KEY_RIGHT)){// rotate the object itself about the specified vector// this changes object orientation, but camera does not moveworld *= mat4::rotation(1.0f, vec3(0.0f, 1.0f, 0.0f));}...}// calculate a new world view projection based on the camera, view, and// the world containing the objectwvpMatrix = proj * view * world;// pass the calculated matrix as a uniform to the vertex shader// the first parameter is the name of the uniform variable// the second parameter is the actual matrix datacontext->setUniformMatrix("WORLD_VIEW_PROJECTION", wvpMatrix);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);}// Draw the objectcontext->drawArrays(GL_TRIANGLE_STRIP, 0, 2);...}while ( context->update() );The vertex shader code in Example 6-25 calculates the position of a fragment based on theinterpolated POSITION value and the WORLD_VIEW_PROJECTION uniform:Example 6-25 Simple world view projection calculation in vertex shaderattribute vec4 POSITION;// position of a point on the primitive shapeattribute vec4 COLOR;// interpolated color from vertex colorsuniform mat4 WORLD_VIEW_PROJECTION; // transformation matrix passed as a uniformvarying vec4 vColor// parameter to pass to the fragment shaderARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-19ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!