Android OpenGL ES – Mipmaps

I am currently a little bit experimenting with Android and its SDK as I am proud owner of a HTC Magic as well as I am pretty impressed by the SDK, Android itself and the ideas and principles it follows.
More precisely I am playing around with the graphical functionalities of Android, especially OpenGL. Android contains an OpenGL ES implementation, therefore I am playing around with some OpenGL codes and test the capabilities and results.

So, I was testing some texturing and of course wanted to test the mipmapping possibilities. Here I tripped over some “problems” you have to avoid by going another way.
In a probably classical way you could use glu to build the mipmaps

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, sizeX, sizeY, GL_RGB, GL_UNSIGNED_BYTE, data);

You hand it the width and height and the texture data and it creates all your needed mipmaps. Problem solved! Unfortunately Android only provides a very small GLU implementation with some helper functions and does not provide you that functionality. Therefore, you would have to go another way.
A possibility on an Android system could be to test for version 1.1 of your GL and use the according hint, as 1.1. adds automatic mipmap generation

gl.glBindTexture(GL10.GL_TEXTURE_2D, textureID);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_NEAREST);
if(gl instanceof GL11) {
  gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
  GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
} else {
  buildMipmap(gl, bitmap);
}

For the emulator this might work but not every mobile device running Android must have a GL11 instance. Therefore, this solution can work but does not necessarily have to.
Mike Miller had a similar problem/idea and suggested the following functionality

private void buildMipmap(GL10 gl, Bitmap bitmap) {
  //
  int level = 0;
  //
  int height = bitmap.getHeight();
  int width = bitmap.getWidth();

  //
  int[] textures = new int[1];
  gl.glGenTextures(1, textures, 0);
  textureID = textures[0];

  //
  gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);

  //
  while(height >= 1 || width >= 1) {
    //First of all, generate the texture from our bitmap and set it to the according level
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bitmap, 0);

    //
    if(height == 1 || width == 1) {
      break;
    }

    //Increase the mipmap level
    level++;

    //
    height /= 2;
    width /= 2;
    Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, width, height, true);

    //Clean up
    bitmap.recycle();
    bitmap = bitmap2;
  }

  return textureID;
}

The code is pretty straight forward. It just creates always the mottled bitmap and adds it using GLUtils to the according level, beginning from 0 to whatever level the size 1 for width or height will be.
Unfortunately again, this did not work for me. I tried this in an existing code I had, a special plain project just for mipmap testing, with different AVDs and with different circumstances. Nothing worked! As soon as I added another layer the texture stayed white. I am aware that as soon as you set the texture parameters for mipmapping

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_NEAREST);

it wants all layers. The function posted by Mike provides these but still it did not work for me. I had no idea why it did not work, because that it is a common solution, trivial and eventually should work. (Nevertheless, I solved it. Read at the end of this post why it did not work for me.)
I do not remember why I tried the following, but after many hours and lost hair I replaced the line of GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bmp, 0); with the following, actually resembling what GLUUtils should provide, but based on an older SDK version

ByteBuffer bytebuf = ByteBuffer.allocateDirect(bmp.getHeight() * bmp.getWidth() * 4);
bytebuf.order(ByteOrder.nativeOrder());
IntBuffer pixelbuf = bytebuf.asIntBuffer();

for(int y = 0; y < bmp.getHeight(); y++)
  for(int x = 0; x < bmp.getWidth(); x++) {
    pixelbuf.put(bmp.getPixel(x, y));
  }
pixelbuf.position(0);
bytebuf.position(0);

gl.glTexImage2D(GL10.GL_TEXTURE_2D, level, GL10.GL_RGBA, bmp.getWidth(), bmp.getHeight(), 0, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixelbuf);

This basic self-implementation of what should be done by GLUtils works for me. But please note that it is just a working example and does is neither optimized nor necessarily the finite solution to this task.

I also figured out why the GLUtils did not work for me: It was only in the Emulator and it was only on one of my machines. And especially that machine it did not work on has a very basic, cheap, old graphics card. But for a whole overview and if you step into the same trap, I posted everything so you know what could be a reason and how to solve it.

So, now after all these tests I have done I have three implementations that work for me. On the one hand side, the use of GL11 and the self-implementation of a mipmap building method in two ways. In conclusion after all these tests and also minor performance tests I did, use one of the suggested methods from above or let me know of other possibilities. I would start with the GL11 test and then go over to the implementations. GLUtils should always work. Hope this helps…

"Our father" IT-Crowd-Nerd-Style

Me and a friend just did a german-it-crowd-computer-nerd-translation of “Our father” inspired by a friend of us. I just had to post it as we think its perfectly fitting:

Platte die du bist im Rechner,
Geheiligt werde dein Speicher,
Deine Bits kommen,
Dein Raid geschehe,
wie im Router so im Desktop.
Unser täglich Video gib uns heute.
Und vergib uns unsere Crashs,
wie auch wir vergeben unseren Controllern.
Und führe uns nicht in ScanDisks,
sondern erlöse uns von Defrags.
Denn dein ist das Bit und das Byte
und die Error in Ewigkeit > /dev/null

3DRealms shuts down!

http://www.shacknews.com/onearticle.x/58519

How? This cannot be possible. This must be a joke. Please be joking. In reality they finished Duke Nukem 4 Ever and will release it. Broussard told everyone that they hit a milestone. This must be marketing.

Update 5

Somehow the Duke still lives (of course)! Scott Miller posted at his Facebook site that the current state is more of a pause than the death of the Duke (who can never die as we all know ^^’). Also some new images emerged with the post. I think they are great and have to still believe that I will see the Duke again.

Update 4

Now, some new footage popped up. Actually it is no new footage but the full segment not shown on the Jace Hall show, when he visited 3DRealms and had the chance to play it. I think it looks actually good and somehow finished. The idea with the controlling tentacles look good and the weapons are awesome as always. I really hope we will see this game in some time…

Duke Nukem Forever played by Jace Hall

Update 3

After more and more news about how 3DRealms possibly refused 30 Millions and Take 2’s action of suing 3DRealms for 12 Millions and Source Code as well as Assets the first, more or less official statement has been made by the remaining executives at 3DRealms. It seems that 3DRealms still exists as a company but had to let go of all their developers in the beginning of May. Everything stated can be interpreted in many ways but I still have hope. It was also reported that Miller, Broussard and other Executives will give a full official statement some time later. So let’s hope everything gets at least clarified.

Update 2

Voodoo Extreme got their hands on 28 Hi-Res Screenshots of the “probable” game. The screens also contain a set of Story Tables/World Chart offering what Duke Nukem Forever could have been. The video below already showed our favourite “Stadium” level (but I liked “L.A. Rumble” more ^^’) and it seems that this would have been the entry into the game, as Duke plays his “historical documents” as a game, in the game. I am sorry, but again I need a moment…*morphingtoweepingwillow*

Update

One of the 3DRealms Animators Bryan Brewer, who worked on Duke Nukem Forever, released a Reel of his work done for the game. If this is the real deal, and this is actual gameplay footage with some story hints and everything, this would have been exactly everything a Duke3D BNC-Net gamer could have wished for. I am sorry, but I need a moment…*cryingoutloud*

Duke Nukem Forever (2007)

The new Adventures of old Monkey Island

Update
Tales of Monkey Island is available. Head over to Telltale Games and download the demo!

Tomorrow Telltale Games will release its interpretation of new Tales of Monkey Island. Based on its known Engine, with a new Storyline split into 5 episodes of enormous fun (at least I hope… and I am pretty sure about it). I will post more about it during the week as I pre-ordered it, of course. But for now, a small trailer…

Tales of Monkey Island (2009)

Bow Street Runner

I just stumbled upon a very good and fascinating adventure made with Macromedia Flash (I do not accept that Adobe bought it ^^’). It is called “Bow Street Runner” on the Channel4 site. It is a historical FMV adventure (so, please have a broadband connection for this) that tells a crime story in London in its 1750s and the Runners in Covent Garden.

Bow Street Runner - Crime Scene
Bow Street Runner – Crime Scene

The wonderful created game gives you the ability to search around, look at evidence, talk to people and try to chit-chat them into giving you clues. “Bow Street Runner” uses real actors playing their parts very well and are staged into the pre-rendered backgrounds you can traverse (basically like Myst, but with far more fluent and accurate controls).
In addition to simple pixel hunting there are extremely well designed action puzzles as you have to pick a lock with specific movements with your mouse or listen to a moving conversation with a jar.
While playing through the game you get the opportunity to try yourself on some mini games as well as you can achieve higher ranks with the Runners as you progress. These can be fasten up as there are special bonus achievements (e.g. save someones life).
As it is a Shockwave game you do not have the chance to save your progress but at the end of every episode you get a special progress code that gets saved onto your computer (probably through a cookie). Additionally you can send this code to your E-Mail address. And as the episodes have a moderate length it is no big negative point.

Bow Street Runner - Suicide?
Bow Street Runner – Suicide?

I have to say the five episodes adventure impressed me. It is made in tradition to old games like Bad Mojo, Tex Murphy, Phantasmagoria, Gabriel Knight and others that were gaming hits in the mid 90s (I liked them!). But in contrary to some bad examples that just made you click yourself through pre-rendered or pre-filmed scenes this one motivates through its distinct art style, historical correctness and the interesting twist between detective work and action riddle solving.

I recommend you go over to the “Bow Street Runner” site and get a picture of what I presented you here about the game. This is a wonderful example of how it should be done to motivate the player and to make a very well furbished game. I hope there will be more games of such caliber as I think these are great games especially to speed up the online game distribution. “You don’t know Jack!” is another example of a wonderful idea predestined for Flash games.

PS: Here is an engine that could be used or extended for such projects ^^’ (No, I would never self-advertise)

The Imagination Enhancer