Tonight I spent some time playing with the native bindings to OpenGL ES on my shiny new Android-based phone, with the eventual far-off goal of porting the Universe client to it. There’s plenty of information on Google about porting C/C++ command line apps and libraries, but nothing that I could see about 3D applications – the closest was this thread which talked about porting a software renderer. So, I figured I’d write this post up with some tips and perhaps spare someone else some pain :)

  • First I followed the steps on this site to download and build the Android source. I used the agcc wrapper script linked off there to simplify compiling, which seems to work fairly well.
  • My test application consists of a coloured triangle, that can be rotated with ‘w’ and ‘d’ on the keyboard. Not very exciting, but it’s enough to test with.
  • ’src/androidgl.cpp’ – This is a quick little library of helper functions I put together to ease the pain of setting up a fullscreen GL context and getting keyboard events. It also contains implementations of some GLU functions, as GLES doesn’t provide them.
  • It’s still rather buggy – I have the same problem as the software renderer guys have with the application ‘behind’ the GL context showing through. This seems to happen whenever an event is signalled – ie: every time I push a key. There’s also a problem with the screen not refreshing properly when the application exits. Both of these issues could probably be solved by using a minimal java program that would invoke the C++ binary, instead of just running it from the shell.

Anyway, the source is here, should anyone find it helpful:

http://bieh.net/svn/androidgl/

Assuming you have the Android toolchain, agcc script and adb set up properly, ‘make && make run-app‘ should compile, push the binary to the phone over adb and execute it. Note that /sdcard is unhelpfully mounted noexec, so I used /cache instead.

In a previous post, I mentioned that I was working on improving the water rendering, something that I feel has always been somewhat lacking in Universe. I picked it up again tonight and made the necessary improvements to the water reflection to deal properly with the curved reflection plane (remember, it’s a planet…).

Basically what you’re seeing there is:

  • Terrain being inversely scaled back towards the center of the planet, then rendered to a low-res reflection texture
  • Modulating the reflection texture with some noise to make refraction (which changes with time as I scroll the noise)
  • A couple more layers of noise being added to make the ‘waves’. I’m not happy with this bit yet, but it looks better than nothing :)

It looks a lot nicer in motion as the waves and refraction move about. I should take a video at some point.