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 2D Shapes3.3 Drawing a rectangle with a custom textureThis section describes how to draw a rectangle and apply a custom texture:1. Locate the tutorial project 07 - Texturing and open the main.cpp file.2. Example 3-1 on page 3-2 shows the standard includes and initialization:Example 3-14 Creating the context for the texture example#include using namespace MDE;int main(){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();#endif// Define the shader sources. Basic texturing shaders.const char* vertexsource ="attribute vec4 POSITION;\attribute vec2 TEXCOORD0;\varying vec2 texcoord;\void main(void)\{\gl_Position = POSITION;\texcoord = TEXCOORD0;\}";const char* fragmentsource ="precision mediump float; \varying vec2 texcoord;\uniform sampler2D texture;\void main(void)\{\gl_FragColor = texture2D(texture, texcoord);\}";...// Create Shader and Program objects:Managed vertexshader = context->createShader(GL_VERTEX_SHADER, vertexsource);Managed fragmentshader = context->createShader(GL_FRAGMENT_SHADER, fragmentsource);Managed program = context->createProgram(vertexshader, fragmentshader);context->setProgram(program);3. A bit-mapped texture is typically read from a file rather than created in the application.This example however defines the texture data and uses it to create a new texture objectas shown in Example 3-2 on page 3-2:ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 3-11ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!