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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Tutorial on Drawing 3D Shapescontext->setUniformMatrix("WORLD_VIEW_PROJECTION", wvpMatrix);}glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);context->drawArrays(GL_TRIANGLE_STRIP, 0, 2); // each cube face uses four vertices with two trianglescontext->drawArrays(GL_TRIANGLE_STRIP, 4, 2); // skip to the next triangle stripcontext->drawArrays(GL_TRIANGLE_STRIP, 8, 2);context->drawArrays(GL_TRIANGLE_STRIP, 12, 2);context->drawArrays(GL_TRIANGLE_STRIP, 16, 2);context->drawArrays(GL_TRIANGLE_STRIP, 20, 2); // last of the six faces}while ( context->update() );}catch (Exception &e){printf(e.getMessage().getCharString());}7. Rebuild the project and run it. Figure 4-3 shows the shape with texturing:Figure 4-3 The cube shape with texturing4.3.1 Converting the vertexBuffer and drawArrays to draw trianglesThe textured cube uses triangle strips for each face of the cube. An alternative way to draw theshape is to draw each triangle individually. The triangle strip or triangle fan approach is typicallyfaster.Modify the example to use triangles:1. Example 4-13 shows how to set the locations for the cube vertices and the correspondinglocations in the texture bitmap.Example 4-13 The vertexData array for the triangle array...GLfloat vertexData[] = {-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, //FRONT 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, 0.0f, // second triangle for front face-0.5f, 0.5f, 0.5f, 0.0f, 1.0f,0.5f, 0.5f, 0.5f, 1.0f, 1.0f,-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, //BACK xyz for vertices, uv for texture-0.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, 0.0f,ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 4-11ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!