Thursday, May 15, 2008

Porting monolithandroid from m3 to m5

The application that I am developing, monolithandroid, currently does not run under m5 series SDK. Why? My app uses OpenGL/ES and there have been significant changes to the way OpenGL/ES works under android from m3 to m5. In a nutshell, in m3 you can use a plain view and intermix OpenGL and Canvas calls. In m5 this is not currently allowed. This was a major problem because the onPaint method of the View Object was used to draw text such as score and level information, as well as the application backdrop (a picture of the moon). There are ways to circumvent these problems and fix the application so that it works on m5. How? You can use a SurfaceView to draw the OpenGL objects, and you can use an overlay to draw text on top of the SurfaceView. And the backdrop? Actually you can use a textured image (an OpenGL object) to draw the backdrop, with the added bonus that you can easily rotate and scale the image. To sum up, monolithandroid under m3 used a class named GLView to draw everything on screen. For m5, 4 new classes were introduced in place of GLView:

GameOverlay (used for drawing status text and scores)

GameSurfaceView (used for holding a surface for OpenGL drawing)

GLThread (used for actually drawing OpenGL objects)

Square (used to load a textured square for the backdrop image of the moon)

It is under svn->trunk->monolithandroid->src->org->teacake->monolithSo after I made these changes, monolithandroid sort of works. However, there are some problems to be addressed, like the time it takes on startup to load the moon image and convert it into a texture.I would like to take the opportunity to thank Ed Burnette for sending me a preview PDF of his forthcoming android book, "HelloAndroid", and I must say that it looks very, very promising. Way to go, Ed! You can find out more about it at: http://www.pragprog.com/categories/upcomingI admit that I shamelessly copied some code (the code for loading textures) from it.Also I would like to thank plusminus and all the guys at http://www.anddev.org where you can find many interesting tutorials, like the following: http://www.anddev.org/textured_cube_opengl_code_sample-t813.htmlExcellent work, guys.