Saturday, May 24, 2008

As you may recall, I use textures to draw the moon backdrop for my android application, monolithandroid. Originally, I only used one texture and I used some code from Ed Burnette's forthcoming book "Hello, Android". However, I decided to add more textures in order to improve the game's graphics. So I created a class named GLTextures, that can be used to make working with multiple textures easier.
Here's the code:
package org.teacake.monolith.apk;
import javax.microedition.khronos.opengles.*;

So, what can you use this code for?
This code enables you to load resources as textures.
At first you create a GLTextures object like this:
GLTextures textures = new GLTextures(gl, context);

Then you add the resource images you want to use as textures:
this.textures.add(R.drawable.moon);
this.textures.add(R.drawable.earth);

And then you loadup the textures:
textures.loadTextures();

When you want to use the texture in your OpenGL code, you can use:
textures.setTexture(R.drawable.moon);
.
.
//OpenGL drawing code
.
.

Actually the setTexture() method calls glBindTexture() which sets the current texture to the correct one.
Of course, you have to enable textures in your OpenGL code in order to do that! If you want more details and examples study the classes GLThread, Square and GLTextures found at http://code.google.com/p/monolithandroidAs you may find, loading pictures and converting them to textures can take a lot of time, so one improvement that you can make is to create a caching scheme. You can, for example, store the textures in a file, after converting them from a picture for the first time, so the next time the application is run, it will load the textures without having to do a conversion. Happy hacking!

Sunday, May 18, 2008

I think that android has a few problems in the area of sound/music playback. After much digging, the only way that I have found to play back music and sound effects is android.media.MediaPlayer. I wanted to add music and sound effects to my game monolithandroid. So I came up with the following class, aptly named SoundSystem. This class uses a separate thread for playback, because we don't want our sound to slowdown our game rendering.

Notice that we use a MediaPlayer object for each sound. I don't know how heavyweight the MediaPlayer object is, and if it is suitable for use for playing 10's or even 100's of sounds. So that could be a problem if you use a lot of sounds for your game. Also, we use synchronous playback, and that could be a problem, too, if our sounds are long. But since it is only version 1.0, it will be improved

Thursday, May 15, 2008

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.

Friday, May 9, 2008

A couple of hours ago I received an email from google that informed me that I am not one of the winner of Android Developer Challenge. To tell you the truth I was not dissapointed. I did not put a lot of hours behind my application, it did not exploit a lot of the platform features and more importantly, it was unoriginal. I am sure that Google's intent behind Android Developer Challenge is to promote original applications, that showcase their platforms strengths. MonolithAndroid (my app) on the contrary only shows OpenGL/ES and touch screen functionality.To sum up (monolithandroid versus the winning apps):So from the above, it is easy to see why my poor tiny app did not win ADC, and why I am not whining about it. The question is, can this meek app be transformed into a winner? I don't know, but I will do my best to make it better. And since it is open source, you can take a shot at it!On Monday we will probably have more information about the winning applications, and see how good they are. Until then, congratulations to the winners (for winning!) and the loosers (for trying). Cheers, guys.