08. OpenGL on Android

  • Description: OpenGL, OpenGL ES, accessing GPU features with NDK
  • Practical part: Create GPU-using apps

Lecture

Practical

Lab archive: lab-8.zip Lab solutions: lab-8-solved.zip

If running the emulator from command line make sure to add the OpenGL libraries to the path: export LD_LIBRARY_PATH=/opt/intel/beaconmountain/ADT/sdk/tools/lib/:$LD_LIBRARY_PATH

Task 1 - Draw a square instead of a triangle

Polygons in OpenGL are made up of multiple triangles. To draw a square, you have to draw two triangles. Modify the lab starter code such that it draws a colored square. Remember, respect clockwise or counter clockwise order for drawing polygons, otherwise you will have problems later on.

(Hint: GL_TRIANGLE_STRIP)

Task 2 - Move the camera with gestures

To use gestures, you have to add an OnTouchListener to the view or overwrite the onTouchEvent of the activity or GLSurfaceView. The received MotionEvent will contain the gesture type and the position. You want to capture ACTION_MOVE and get X and Y position, and then transmit them to the step method, and use them for modifying one of the rotation parameters (rx, ry, or rz). Remember to return true, otherwise you will not receive any more events.

Task 3 - Using Android debugging capabilities

Look in the settings menu under “Developer Options”.

There are 4 options of interest:

  • Debug GPU overdraw - this shows which parts of the screen are drawn over more than once. If there are many part of the screen updated more than once it can lead to performance problems. Clip the objects which are not visible.
  • Debug Non Rectangluar Clipping Operations - see parts clipped using the stencil buffer (helpful to debug stencil buffer)
  • Profile GPU rendering - draws bars or lines on screen to determine how long it takes to update a view (blue is how long it takes to create commands, orange is how long it takes to issue commands, and yellow is how much it takes to draw the commands) or through dumpsys gfxinfo.
  • Enable OpenGL traces - creates traces to use with Tracer or to inspect visually.

Task 4 - Use Tracer for OpenGL ES

In Eclipse switch to Tracer perspective (Window > Open Perspective > Other). In the context bar there should be two new icons: Open existing trace and Connect to a device. Use the second one, choose the device and use the package and activity name of the application: package com.android.gl2jni and activity GL2JNIActivity.

ndk/courses/08.txt · Last modified: 2014/06/16 14:55 by petre.eftime
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0