+ All Categories
Home > Documents > Fast and Rich Animations For Your Android Apps Using OpenGL ES

Fast and Rich Animations For Your Android Apps Using OpenGL ES

Date post: 06-Mar-2015
Category:
Upload: indicthreads
View: 367 times
Download: 2 times
Share this document with a friend
Description:
Presented By Kauserali Hafizji at the 2nd IndicThreads.com Conference On Mobile Application Development, August 2011 http://Mobile.IndicThreads.com
33
1 Fast and Rich animations for Android Apps using OpenGL ES Kauserali Hafizji June Software
Transcript
Page 1: Fast and Rich Animations For Your Android Apps Using OpenGL ES

1

Fast and Rich animations for Android Apps using OpenGL ES

Kauserali HafizjiJune Software

Page 2: Fast and Rich Animations For Your Android Apps Using OpenGL ES

2

About Me• @ Tap N Tap

• Android UI Toolkit for Tablets

• @ CrowdSpottr • Built the android version

• @ June Software• 2d Games for iOS and

Android

Page 3: Fast and Rich Animations For Your Android Apps Using OpenGL ES

3

This is ! a gaming session

Page 4: Fast and Rich Animations For Your Android Apps Using OpenGL ES

4

Agenda• Understand why OpenGL ES for

Android Apps• Anatomy of an OpenGL ES

Implementation• My experiences of using OpenGL ES• QnA

Page 5: Fast and Rich Animations For Your Android Apps Using OpenGL ES

5

Why OpenGL ES?

Page 6: Fast and Rich Animations For Your Android Apps Using OpenGL ES

6

Sdk Animations

• Animations can be done in 2 ways:• Tweened animation• Frame by frame animation

Page 7: Fast and Rich Animations For Your Android Apps Using OpenGL ES

7

When to use default animations ?

• Only in cases of simple animation requirements.

• Default animations are not sufficient for complex animations.

Page 8: Fast and Rich Animations For Your Android Apps Using OpenGL ES

8

Sample complex animations

Inbuilt Gallery3d App built in OpenGL ES.

Page 9: Fast and Rich Animations For Your Android Apps Using OpenGL ES

9

Talking Tom app • Easy to build with

OpenGL ES.

Page 10: Fast and Rich Animations For Your Android Apps Using OpenGL ES

10

Case Study: Sample Animation

Page 11: Fast and Rich Animations For Your Android Apps Using OpenGL ES

11

1. Using Simple Views

Animate the views on the UI Thread itself.

Problems• Slow

• Each movement causes an invalidate on the parent view.

Page 12: Fast and Rich Animations For Your Android Apps Using OpenGL ES

12

2. Using the canvasUse the canvas to draw elements.Pros

• Is optimized since invalidation is on a part of the view.

Cons• For heavy items to be rendered, FPS

reduces drastically rendering a jerky motion.

Page 13: Fast and Rich Animations For Your Android Apps Using OpenGL ES

13

3. OpenGL ESUse OpenGL to render the elements.Pros

• All the rendering happens in one view and we don’t have to worry about invalidations.

• Can render 2X-5X of regular FPS.

Cons• Programming intensive.

Page 14: Fast and Rich Animations For Your Android Apps Using OpenGL ES

14

What is OpenGL ES?

• Cross-platform API for full function 2D and 3D graphics on embedded systems.

• Works as an interface between software and graphics acceleration.

Page 15: Fast and Rich Animations For Your Android Apps Using OpenGL ES

15

State machine architecture

Page 16: Fast and Rich Animations For Your Android Apps Using OpenGL ES

16

OpenGL ES Basic Terminology• Co-ordinate Axis• ViewPorts• Vertexes• Polygons• Meshes and Textures• FPS

Page 17: Fast and Rich Animations For Your Android Apps Using OpenGL ES

17

Co-ordinate axis

Page 18: Fast and Rich Animations For Your Android Apps Using OpenGL ES

18

Viewports• Chunk of space that can be seen. • OpenGL ES provides two kinds of

viewports:

1. Perspective projection 2. Orthographic projection

Page 19: Fast and Rich Animations For Your Android Apps Using OpenGL ES

19

Vertexes

• A point in 3d space• X co-ordinate• Y co-ordinate• Z co-ordinate

Page 20: Fast and Rich Animations For Your Android Apps Using OpenGL ES

20

Polygons• The biggest polygon that OpenGL ES

allows you to draw is a triangle.• Anything else needs to be drawn with a

series of triangles.

Page 21: Fast and Rich Animations For Your Android Apps Using OpenGL ES

21

Textures and Meshes• An image in OpenGL is termed as a

texture.• Textures are mapped onto a mesh of

vertices.

3d Mesh Textured Mesh

Page 22: Fast and Rich Animations For Your Android Apps Using OpenGL ES

22

Animations with textured Meshes• Map an image to a mesh.• Move the mesh around in 3d space

according to the animation required.

Page 23: Fast and Rich Animations For Your Android Apps Using OpenGL ES

23

OpenGL ES animation

Press Me

Page 24: Fast and Rich Animations For Your Android Apps Using OpenGL ES

24

FPS – Frames Per Second• Is the number of times onDraw is called

in a second.• Typical code to measure FPS would

look like this:

Page 25: Fast and Rich Animations For Your Android Apps Using OpenGL ES

25

Page 26: Fast and Rich Animations For Your Android Apps Using OpenGL ES

26

Sample OpenGL ES program

Page 27: Fast and Rich Animations For Your Android Apps Using OpenGL ES

27

Getting started with OpenGL ES1. Set up the View.

GLSurfaceView• Glue to connect OpenGL ES to the view system.• Allows OpenGL ES to work with the activity

life cycle.2. Set up the Renderer

GLSurfaceView.Renderer• Provides 3 utility functions:onSurfaceCreatedonDrawFrame onSurfaceChanged

Page 28: Fast and Rich Animations For Your Android Apps Using OpenGL ES

28

In code

Page 29: Fast and Rich Animations For Your Android Apps Using OpenGL ES

29

Common OpenGL ES problems• Introducing the GLSurfaceView in a 2d

app can be resource intensive.• You may notice a flicker at the start.• To overcome Screen Flicker

• Make sure the GLSurfaceView fills the entire screen.

Page 30: Fast and Rich Animations For Your Android Apps Using OpenGL ES

30

References• Jeff Lamarche’s blog

• (http://iphonedevelopment.blogspot.com)

• Man pages• (http://www.khronos.org/opengles/sdk/1.1/docs/man/)

• The red book• (http://www.glprogramming.com/red/)

• OpenGL SuperBible• (http://www.opengl.org/sdk/docs/books/SuperBible/)

Page 31: Fast and Rich Animations For Your Android Apps Using OpenGL ES

31

Conclusion

Page 32: Fast and Rich Animations For Your Android Apps Using OpenGL ES

32

Questions??

Page 33: Fast and Rich Animations For Your Android Apps Using OpenGL ES

33

Thank You

[email protected]• @Ali_hafizji


Recommended