Tips/tricks related to Computer Graphics, GPUs and other programming

Posts tagged ‘android’

Android Performance Case Study

If you are interested in Android development, I highly recommend checking out Romain Guy’s post (Romain is an Android dev at Google) on profiling and optimizing an application.


All applications should ideally take at most 16 ms to execute one frame, achieving a smooth  framerate of 60 frames per second. Romain goes over some crucial new tools like systrace and TraceView which work with Android Jellybean (4.1 and 4.2)


If you are getting an Android device, make sure it’s a Nexus

I had a Samsung Galaxy Captivate for 2 years before I upgraded to a HTC One X. While both phones are pretty good, the lack of software updates is extremely frustrating.


Samsung took forever to release Gingerbread (version 2.3) for the Captivate. By the time they released it people were already running Ice cream sandwich (4.0) ROMS on it. I got frustrated and switched to an ICS ROM, though playing around with ROMS can be another headache.


As for the One X, it is a gorgeous phone with a wonderful screen, but HTC promised a Jelly Bean (4.1) update by the end of 2012, and here we are in 2013. It is simply frustrating for users who want to be on the bleeding-edge (yes you can root your phone and install a new ROM, but I was unable to since AT&T has heavily locked down their phones). 


In the meantime Google released the Nexus 4 in 2012, which came with 4.2 (will the One X ever get 4.2? Probably not). Even the 2-year old Nexus S got updated to 4.1 quickly (though it won’t be getting 4.2). 


I place the blame on the carriers, since HTC has released the JB update for worldwide phones. AT&T and other carriers like to load the phones with a lot of crappy apps which you can’t get rid of. I just want a pure and straightforward Android experience. It also doesn’t help that manufacturers like HTC and Samsung like to modify Android themselves to make it more distinct, but in my opinion it only slows down the Android experience and doesn’t add a lot. 


As for tablets, the same rule applies. Get a Nexus 7 or a Nexus 10.


There is a reason why Apple preferred to have total control over the iPhone software experience – and which is why you should get a Nexus device, free from the constraints of manufacturers and clueless carriers.

Android OpenGL ES 2.0 – Shadow Mapping

NOTE: This tutorial builds up on my previous 2 tutorials: how to setup OpenGL ES 2.0 on Android and how to render to texture.

I’ll first link to the apk, source code and the repository:
apk here.
Source code here.
Google Code Repository  here. NOTE: Branch is “shadowMapping”


Thanks to Henry’s comment below I was able to fix most of the artifacts showing up. Turns out I had dithering enabled, so I had to disable it to remove the dithering effect [ GLES20.glDisable(GLES20.GL_DITHER) ]. Updated images below – it works but has very slight artifacts when it comes to the mesh’s self-shadows.


Shadow Mapping is a popular technique for rendering shadows in games and other real-time applications. Given how GPUs on mobile devices (iPhone/Android/whatever) are getting more and more powerful every day I thought I might try implementing it on my Samsung Captivate (Galaxy S).

While my implementation “works”, it does not good look at all. Shadow-mapping is prone to many artifacts , which I wasn’t able to properly fix (UPDATE: Main artifacts fixed).I am posting this without the fix in the hopes that somebody can help me out too as to what I am doing wrong.

Here are the updated images (I changed the color of the plane to get a better contrast):

Textured Cube (with proper shadows)

Dragon Head


Here are the old images:

Octahedron Mesh (.OFF) with shadows + artifacts

Dragon-head Mesh (.OFF)

Textured Cube (.OBJ)

I would like to credit Fabien Sanglard for his shadow mapping tutorials which I used as a basis for my code. I looked at his DEngine code as an example. In any case let’s begin.

What is Shadow Mapping?

If you are reading this chances are that you already know what shadow mapping is and how it works, but let me give a quick overview of the steps involved:


Android OpenGL ES 2.0 – Render To Texture

NOTE: This tutorial builds up on my previous tutorial on how to setup OpenGL ES 2.0 on Android.

I’ll first link to the apk, source code and the repository:
apk here.
Source code here.
Google Code Repository  here. NOTE: Branch is “renderToTex”

Rendering to a texture is important when it comes to various graphics techniques and algorithms (Shadow Mapping, cube map generation, Deferred Shading, etc.) So this quick tutorial will demonstrate how to setup a texture for rendering (and then how to display that texture on screen).

What is rendered to the texture?
We are going to render the same objects as in the previous tutorial (where you can choose between gouraud/phong/normal mapping shaders). The texture is going to be a simple quad which will then be displayed on the full screen. I have a Samsung Captivate(Samsung Galaxy S) which has a screen resolution of 800 X 480, so I use those values as the height and width of my texture. Adjust accordingly to your phone (I was a tad lazy to read in the values from the system itself). Let’s begin:


Getting started with OpenGL ES 2.0 shaders on Android

Tutorials on how to write shaders for the Android platform are a little difficult to come by on the Internet, so I decided to work on a small but simple program which hopefully provides a simple framework to get started writing programs for OpenGL ES 2.0.

I’ll first link to the apk, source code and the repository:
apk here.
Source code here.
Google Code Repository  here. NOTE: Branch is “default”

Here’s what my program does:

  • Mesh Loading:The program loads triangular meshes in these formats (as .txt files):
    • (.OFF): These consist of only vertex positions. My program will calculate per-vertex normals.
    • (.OBJ): Vertex positions, normals and texture coordinates are provided. Sample textured cube mesh was exported from Blender.
  • Shaders:
    • Gouraud Shading: Per-vertex lighting [with texture mapping if enabled].
    • Phong Shading: Per-pixel lighting [with texture mapping if enabled].
    • Normal Mapping: Gives a fake appearance of depth to a mesh. Sample normal map included.

NOTE: If your program is crashing with glError 1281 and you have a relatively new phone (a Samsung Galaxy S2 for example), change all dot() method calls in the shaders to dot2().

How it works:

The program will only work if your phone supports OpenGL ES 2.0. If it doesn’t my program quits without a warning.

When the program starts you will see an octahedron mesh with Gouraud shading enabled. There is a light rotating around the mesh. You can use one finger
to rotate the mesh, and two fingers (pinch-to-zoom) to scale the mesh (though it’s not *perfect* ). Clicking the menu button on your phone allows you to:

  • Toggle Light Rotation: Light rotation can be toggled through this option. A short ‘Toast’ notification pops up.
  • Shader switching: Can switch between Gouraud shading, phong shading and normal mapping.
  • Mesh switching: Can switch between an Octahedron, Tetrahedron (both .off files) and Textured Cube Mesh (.obj file).
  • Toggle Texturing: Can turn off texture mapping if there is an associated texture with the object (only the textured cube mesh).