Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg



Similar documents
Aston University. School of Engineering & Applied Science

An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June

Computer Graphics on Mobile Devices VL SS ECTS

Introduction to Computer Graphics

4BA6 - Topic 4 Dr. Steven Collins. Chap. 5 3D Viewing and Projections

Image Processing and Computer Graphics. Rendering Pipeline. Matthias Teschner. Computer Science Department University of Freiburg

Monash University Clayton s School of Information Technology CSE3313 Computer Graphics Sample Exam Questions 2007

CS 4204 Computer Graphics

Silverlight for Windows Embedded Graphics and Rendering Pipeline 1

Graphics Pipeline in a Nutshell

Chapter 2 - Graphics Programming with JOGL

How To Teach Computer Graphics

Beginning Android 4. Games Development. Mario Zechner. Robert Green

OpenGL & Delphi. Max Kleiner. 1/22

Blender Notes. Introduction to Digital Modelling and Animation in Design Blender Tutorial - week 9 The Game Engine

Web Based 3D Visualization for COMSOL Multiphysics

GUI GRAPHICS AND USER INTERFACES. Welcome to GUI! Mechanics. Mihail Gaianu 26/02/2014 1

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

Performance Optimization and Debug Tools for mobile games with PlayCanvas

The mouse callback. Positioning. Working with Callbacks. Obtaining the window size. Objectives

NVPRO-PIPELINE A RESEARCH RENDERING PIPELINE MARKUS TAVENRATH MATAVENRATH@NVIDIA.COM SENIOR DEVELOPER TECHNOLOGY ENGINEER, NVIDIA

Video, film, and animation are all moving images that are recorded onto videotape,

3D Graphics and Cameras

4D Interactive Model Animations

How To Run A Factory I/O On A Microsoft Gpu 2.5 (Sdk) On A Computer Or Microsoft Powerbook 2.3 (Powerpoint) On An Android Computer Or Macbook 2 (Powerstation) On

JavaFX Session Agenda

Tegra Android Accelerometer Whitepaper

GearVRf Developer Guide

Finger Paint: Cross-platform Augmented Reality

A. OPENING POINT CLOUDS. (Notepad++ Text editor) (Cloud Compare Point cloud and mesh editor) (MeshLab Point cloud and mesh editor)

Programming 3D Applications with HTML5 and WebGL

KIVY - A Framework for Natural User Interfaces

TEACHING GRAPHICS PROGRAMMING ON MOBILE DEVICES

Transformations in the pipeline

Game Development in Android Disgruntled Rats LLC. Sean Godinez Brian Morgan Michael Boldischar

Adobe Illustrator CS5 Part 1: Introduction to Illustrator

An Introduction to. Graphics Programming

DIALux. evo 1. User Manual. The Software Standard for Calculating Lighting Layouts

Google Android Syllabus

WebGL based E-Learning Platform on Computer Graphics

Cortona3D Viewer. User's Guide. Copyright ParallelGraphics

Mocean Android SDK Developer Guide

Introduction to WebGL

CREATE A 3D MOVIE IN DIRECTOR

Optimizing Unity Games for Mobile Platforms. Angelo Theodorou Software Engineer Unite 2013, 28 th -30 th August

Part I. Basic Maths for Game Design

Color correction in 3D environments Nicholas Blackhawk

CLOUD DIGITISER 2014!

1 ImageBrowser Software Guide

Introduction to NaviGenie SDK Client API for Android

Realtime 3D Computer Graphics Virtual Reality

Affdex SDK for Windows!

The Car Tutorial Part 1 Creating a Racing Game for Unity

CSE 564: Visualization. GPU Programming (First Steps) GPU Generations. Klaus Mueller. Computer Science Department Stony Brook University

COMP175: Computer Graphics. Lecture 1 Introduction and Display Technologies

Introduction to Autodesk Inventor for F1 in Schools

Graduate presentation for CSCI By Janakiram Vantipalli ( Janakiram.vantipalli@colorado.edu )

This tutorial assumes that Visual3D has been installed and that a model has been created as described in Tutorial #1.

WEARIT DEVELOPER DOCUMENTATION 0.2 preliminary release July 20 th, 2013

3D Modeling Using Stereo Projection

ECE 455/555 Embedded System Design. Android Programming. Wei Gao. Fall

Welcome to CorelDRAW, a comprehensive vector-based drawing and graphic-design program for the graphics professional.

INTRODUCTION TO RENDERING TECHNIQUES

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

How To Draw A Billiards Ball In Gta 3D With Texture Mapping (Gta 3) On A Computer Or 2D Or Gta 2D (Gt) On Your Computer Or Computer Or Your Computer (Or Your Computer)

Developing Applications for ios

Tutorial 9: Skeletal Animation

Android Sensors. CPRE 388 Fall 2015 Iowa State University

Kathy Au Billy Yi Fan Zhou Department of Electrical and Computer Engineering University of Toronto { kathy.au, billy.zhou }@utoronto.

Geosoft Technical Note Working with 3D Views in Oasis montaj

! Sensors in Android devices. ! Motion sensors. ! Accelerometer. ! Gyroscope. ! Supports various sensor related tasks

Selection and Zooming using Android Phone in a 3D Virtual Reality

A Short Introduction to Computer Graphics

Writing Applications for the GPU Using the RapidMind Development Platform

ANDROID PROGRAMMING - INTRODUCTION. Roberto Beraldi

CS 528 Mobile and Ubiquitous Computing Lecture 2: Android Introduction and Setup. Emmanuel Agu

3D Viewing. Chapter 7. Projections. 3D clipping. OpenGL viewing functions and clipping planes

Introduction to ANSYS ICEM CFD

Shader Model 3.0. Ashu Rege. NVIDIA Developer Technology Group

Getting Started with CodeXL

Introduction to Autodesk Inventor for F1 in Schools

Effective Use of Android Sensors Based on Visualization of Sensor Information

OpenGL Performance Tuning

OpenGL Insights. Edited by. Patrick Cozzi and Christophe Riccio

Tutorial 13: Object Animation

Lecture Notes, CEng 477

Android Sensor Programming. Weihong Yu

Optimizing AAA Games for Mobile Platforms

Develop Computer Animation

ALON MP3 Dictaphone. User's manual. 1. Introduction 2. Audio Player 3. Voice Dictaphone 4. Phone calls recorder 5. Customer support.

Overview. About Interstitial Ads: About Banner Ads: About Offer-Wall Ads: ADAttract Account & ID

1.0-Scratch Interface 1.1. Valuable Information

GeoGebra. 10 lessons. Gerrit Stols

Instructions for Creating a Poster for Arts and Humanities Research Day Using PowerPoint

Cookbook. Flash ios Apps. Christopher Caleb. 100 practical recipes for developing ios apps with Flash Professional and Adobe AIR PUBLISHING MUMBAI

REMOTE RENDERING OF COMPUTER GAMES

BlackVue Cloud App Overview...3. Getting Started...6. Basic Menu Screens BlackVue Cloud BlackVue Wi-Fi Internal Memory...

Solar Tracking Controller

3D Modeling and Simulation using Image Stitching

Graphics Input Primitives. 5. Input Devices Introduction to OpenGL. String Choice/Selection Valuator

Transcription:

Android and OpenGL Android Smartphone Programming Matthias Keil Institute for Computer Science Faculty of Engineering 16. Dezember 2013

Outline 1 OpenGL Introduction 2 Displaying Graphics 3 Interaction 4 Notes 5 Summary Matthias Keil Android and OpenGL 16. Dezember 2013 2 / 24

OpenGL Introduction Short for: Open Graphics Library[4]. Enables creation of 2D and 3D graphics. Special API for embedded systems available on Android: OpenGL ES API. Two important classes: GLSurfaceView and GLSurfaceView.Renderer. Matthias Keil Android and OpenGL 16. Dezember 2013 3 / 24

OpenGL Introduction Important Classes GLSurfaceView View to draw and manipulate objects using OpenGL. GLSurfaceView.Renderer Interface defining methods to draw (render) graphics. Add renderer to GLSurfaceView using GLSurfaceView.setRenderer(). Extend GLSurfaceView to capture touch screen events. Extend Android manifest when using OpenGL ES 2.0: 1 <! -- Tell the system this app requires OpenGL ES 2.0. --> 2 <uses - feature android:glesversion ="0 x00020000 " android:required =" true " /> Matthias Keil Android and OpenGL 16. Dezember 2013 4 / 24

OpenGL Introduction Example 1 class MyGLSurfaceView extends GLSurfaceView { 2 public MyGLSurfaceView ( Context context ){ 3 super ( context ); 4 setrenderer ( new MyRenderer ()); 5 // Called when using OpenGL ES 2.0 6 seteglcontextclientversion (2) ; 7 } 8 } Matthias Keil Android and OpenGL 16. Dezember 2013 5 / 24

OpenGL Introduction GLSurfaceView.Renderer Includes three methods to be implemented to draw graphics. onsurfacecreated() Called once when creating the GLSurfaceView. Should include all actions to do only once. ondrawframe() Called on each redraw of GLSurfaceView. Do all drawing and redrawing of graphic objects here. onsurfacechanged() Called when the geometry of GLSurfaceView changes, for example size screen or orientation. Add code to respond to those changes. Matthias Keil Android and OpenGL 16. Dezember 2013 6 / 24

OpenGL Introduction Versions Two different OpenGL ES API versions available: 1.0 (together with version 1.1 extensions) and 2.0. Both usable to create high performance graphics for 3D games and visualizations. Grapic programming for one of the versions differs significantly to programming for the other version. Version 1.0/1.1 is easier to use as there are more convenience methods available. Version 2.0 provides higher degree of control, enabling creating of effects that are hard to realize in version 1.0/1.1. Matthias Keil Android and OpenGL 16. Dezember 2013 7 / 24

Defining Shapes Shapes are graphic objects to be drawn in OpenGL. Shapes are defined using three-dimensional coordinates. Coordinates get written into ByteBuffer that is passed into the graphics pipeline for processing. Coordinate format: [X, Y, Z] Examples: Center of view: [0,0,0], top right corner: [1,1,0], bottom left corner: [-1,-1,0]. Matthias Keil Android and OpenGL 16. Dezember 2013 8 / 24

Example: Defining Triangle 1 class Triangle { 2 private FloatBuffer vertexbuffer ;... 3 public Triangle () { 4 // initialize vertex byte buffer for shape coordinates (4 bytes per coordinate ) 5 ByteBuffer bb = ByteBuffer. allocatedirect ( trianglecoords. length * 4); 6 // use the device hardware s native byte order 7 bb. order ( ByteOrder. nativeorder ()); 8 // create a floating point buffer 9 vertexbuffer = bb. asfloatbuffer (); 10 // add the coordinates to the FloatBuffer 11 vertexbuffer. put ( trianglecoords ); 12 // set the buffer to read the first coordinate 13 vertexbuffer. position (0) ; 14 }} Matthias Keil Android and OpenGL 16. Dezember 2013 9 / 24

Drawing Shapes Vertex Shader Contains code for rendering the vertices of a shape. Fragment Shader Contains code for rendering the face (visible front) of shape with colors or textures. Program OpenGL ES object containing shaders used. At least one vertex shader and one fragment shader needed to draw a shape. Both shaders must be compiled and then added to the program. Matthias Keil Android and OpenGL 16. Dezember 2013 10 / 24

Mapping Coordinates for Drawn Objects Problem: Device screen is no square, but OpenGL assumes that[1]. The picture shows what happens. Left: How it should look. Right: How it looks in horizontal orientation. Solution: Use projection modes and camera views to transform coordinates. Matthias Keil Android and OpenGL 16. Dezember 2013 11 / 24

Mapping Coordinates for Drawn Objects Create projection matrix and camera view matrix. Apply both to the OpenGL rendering pipeline. Projection matrix recalculates coordinates of the graphic objects to adjust the screen size. Camera view matrix creates transformation that shows object from specific eye position. Matthias Keil Android and OpenGL 16. Dezember 2013 12 / 24

Example in OpenGL ES 1.0: Projection Matrix Create and use projection matrix in onsurfacechanged() of the GLSurfaceView.Renderer implementation. Use geometry of device seen to recalculate coordinates. 1 public void onsurfacechanged ( GL10 gl, int width, int height ) { 2 gl. glviewport (0, 0, width, height ); 3 float ratio = ( float ) width / height ; 4 // set matrix to projection mode 5 gl. glmatrixmode ( GL10. GL_PROJECTION ); 6 // reset the matrix to its default state 7 gl. glloadidentity (); 8 // Define and apply the projection matrix 9 gl. glfrustumf (- ratio, ratio, -1, 1, 3, 7); 10 } Matthias Keil Android and OpenGL 16. Dezember 2013 13 / 24

Example in OpenGL ES 1.0: Methods Define a projection matrix in terms of six planes. 1 public static void frustumm ( float [] m, int offset, float left, float right, float bottom, float top, float near, float far ) Matthias Keil Android and OpenGL 16. Dezember 2013 14 / 24

Example in OpenGL ES 1.0: Camera Transformation Matrix Apply camera view in ondrawframe() of the GLSurfaceView.Renderer implementation. Use GLU.gluLookAt() to create a transformation simulating the camera position. 1 public void ondrawframe ( GL10 gl) { 2... 3 // Set GL_ MODELVIEW transformation mode 4 gl. glmatrixmode ( GL10. GL_MODELVIEW ); 5 // reset the matrix to its default state 6 gl. glloadidentity (); 7 // When using GL_ MODELVIEW, you must set the camera view 8 GLU. glulookat (gl, 0, 0, -5, 0f, 0f, 0f, 0f, 9... 10 } 1.0f, 0.0 f); Matthias Keil Android and OpenGL 16. Dezember 2013 15 / 24

Example in OpenGL ES 1.0: Methods Define a transformation in terms of an eye point, a center of view, and an up vector. 1 glulookat ( GL10 gl, float eyex, float eyey, float eyez, float centerx, float centery, float centerz, float upx, float upy, float upz ) Matthias Keil Android and OpenGL 16. Dezember 2013 16 / 24

Example in OpenGL ES 2.0: Steps overview 1 Define a Projection[5]. 2 Define a Camera View. 3 Apply Projection and Camera Transformations on all objects to draw. Step 1 and 2 very similar to OpenGL ES 1.0. Matthias Keil Android and OpenGL 16. Dezember 2013 17 / 24

Example in OpenGL ES 2.0: Step 3 Apply Projection and Camera Transformations on all objects to draw. Edit draw method of a shape: 1 public void draw ( float [] mvpmatrix ) {... 2 // get shape s transformation matrix 3 matrix = GLES20. glgetuniformlocation ( mprogram, " umvpmatrix "); 4 // Apply projection and view transformation 5 GLES20. gluniformmatrix4fv ( matrix, 1, false, mvpmatrix, 0); 6 // Draw the shape 7 GLES20. gldrawarrays ( GLES20. GL_TRIANGLES, 0, vertexcount ); 8... 9 } Matthias Keil Android and OpenGL 16. Dezember 2013 18 / 24

Adding Motion Rotation can be simply added using OpenGL ES 2.0 Create rotation matrix and combine it with projection and camera view transformation matrices. Extend ondrawframe method. Matthias Keil Android and OpenGL 16. Dezember 2013 19 / 24

Adding Motion Example 1 float [] mrotationmatrix = new float [ 16]; 2 // Create a rotation transformation for the triangle 3 long time = SystemClock. uptimemillis () % 4000 L; 4 float angle = 0. 090 f * (( int ) time ); 5 Matrix. setrotatem ( mrotationmatrix, 0, mangle, 0, 0, -1.0f); 6 // Combine the rotation matrix with the projection and camera view 7 Matrix. multiplymm ( mmvpmatrix, 0, mrotationmatrix, 0, mmvpmatrix, 0); 8 // Draw shape 9 mtriangle. draw ( mmvpmatrix ); Matthias Keil Android and OpenGL 16. Dezember 2013 20 / 24

Touch Screen Interaction Can be implemented by overriding the method ontouchevent(motionevent) of the class View. MotionEvent gives you various information about where the event happened and how. Example: long MotionEvent.getDownTime() returns the time in ms when user started to press down. Also possible to recover historical/old coordinates of the event[3]. Easy simulation in the emulator possible: Click, hold and move the mouse. Matthias Keil Android and OpenGL 16. Dezember 2013 21 / 24

Notes Class Random can produce a random number[6]. Class Sensor is used to access sensors of the cellphone, e.g. the gyroscope[8]. Class MediaPlayer enables playing of sounds[2]. Usage: Put a sound file into folder res/raw/. Supported file formats include ogg vorbis, wav, mp3 and more. 1 MediaPlayer mediaplayer = MediaPlayer. create ( context, R. raw. soundfile ); 2 mediaplayer. start (); Matthias Keil Android and OpenGL 16. Dezember 2013 22 / 24

Summary Drawing with OpenGL takes place on GLSurfaceView. GLSurfaceView.Renderer is responsile to draw the shapes. Important to decide which OpenGL ES version to take. Shapes are defined using three-dimensional coordinates. Different shaders needed to draw a shape. Projection matrix is used to adjust graphics to the device screen. Camera transformation matrix is used to simulate a camera position. Rotation motion can be added using an additional matrix. Touch screen interaction can be implemented overriding method ontouchevent. Matthias Keil Android and OpenGL 16. Dezember 2013 23 / 24

Bibliography Android Developers. Mapping Coordinates for Drawn Objects. http://developer.android.com/guide/topics/graphics/opengl.html#coordinate-mapping. Android Developers. Media Playback. http://developer.android.com/guide/topics/media/mediaplayer.html. Android Developers. MotionEvent. http://developer.android.com/reference/android/view/motionevent.html. Android Developers. OpenGL. http://developer.android.com/guide/topics/graphics/opengl.html. Android Developers. OpenGL ES 2.0: Applying Projection and Camera Views. http://developer.android.com/training/graphics/opengl/projection.html#projection. Android Developers. Random. http://developer.android.com/reference/java/util/random.html. Android Developers. Tutorial: Displaying Graphics with OpenGL ES. http://developer.android.com/training/graphics/opengl/index.html. Android Developers. Using the Gyroscope. http: Matthias Keil Android and OpenGL 16. Dezember 2013 24 / 24