Mali GPU User Interface Engine Application Development Guide
Mali GPU User Interface Engine Application Development Guide
Mali GPU User Interface Engine Application Development Guide
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.2 Coloring the cube facesThis tutorial shows how to color the cube faces based on the color of the vertices.1. Locate the shader example project 02 Coloring and open the coloring.cpp file.2. The vertexData[] array in Example 4-3 on page 4-3 did not specify the face color.Example 4-7 shows how both the position and color are specified in the vertex array:Example 4-7 Setting the vertex position and color...GLfloat vertexData[] = {// FRONT-0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f,0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f,-0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f,0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f,// BACK-0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 0.0f, 1.0f,-0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 0.0f, 1.0f,0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 0.0f, 1.0f,0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 0.0f, 1.0f,// LEFT-0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f,-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f,-0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f,-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f,// RIGHT0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 1.0f, 1.0f,0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 1.0f, 1.0f,0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 1.0f, 1.0f,0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f, 1.0f,// TOP-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f,0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f,-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 1.0f,0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 1.0f,// BOTTOM-0.5f, -0.5f, 0.5f, 1.0f, 1.0f, 0.0f, 1.0f,-0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 0.0f, 1.0f,0.5f, -0.5f, 0.5f, 1.0f, 1.0f, 0.0f, 1.0f,0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 0.0f, 1.0f,};// x,y,z, r,g,b,alphaManaged vertexBuffer =context->createBuffer(GL_ARRAY_BUFFER, sizeof(vertexData), sizeof(GLfloat)*7);vertexBuffer->setData(0, sizeof(vertexData), vertexData);context->setVertexBuffer(0, vertexBuffer);VertexElement elements[2]; // two elements: xyz for vertex and rgba for colorelements[0].components = 3;elements[0].offset = 0;elements[0].semantic = POSITION;elements[0].stream = 0;elements[0].type = GL_FLOAT;elements[1].components = 4;elements[1].offset = 3*sizeof(GLfloat);elements[1].semantic = COLOR; // the color is determined by the vertex colorelements[1].stream = 0;elements[1].type = GL_FLOAT;ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 4-6ID070710Non-Confidential - Draft - Beta