So far the comments I got for the beta of my Asteroids game were very pleasing. Most people liked it and played the game a couple of times right away. Also the difficulty was more challenging for most players than I expected (with a few exceptions of notorious hardcore gamers). But what makes me most happy is that no major issues or strange crashes were reported! Also the debian package I created in an updated worked and installed all required dependencies. Yesss!
In the mean time I tried to explore the possibilities on how to pimp up the graphics to allow 3D objects flying around. As I am using Blender from time to time I thought of creating a simple Asteroid and import that into my game. However finding a texture that I could use freely and therefore I looked for alternatives. I found a very nice tutorial at http://www.davidjarvis.ca/dave/blender/tutorial-21.shtml on how to create an asteroid by using Blender. The tutorial itself is for Blender 2.44, however I thought I use the chance to play around with the beta version of the new Blender 2.5.
What I really liked about the tutorial was the use of multiple materials to get the surface of the asteroid properly and asteroid like. This had also a very nice benefit as the texture gets created by the materials and I would not have to search for an appropriate (i.e. freely available) one.
Here is a rendered version of my asteroid:
Having finished the asteroid itself I only had to get it into my game. I chose to use the existing Wavefront OBJ format as they are easily exported from most 3D content creation tools and are easy to read. However instead of writing my own version of importer I chose to use the code that was made available under the MIT open-source license (Yay!) at http://www.dhpoware.com/demos/glObjViewer.html. With it I was able to display my first 3D asteroid:
Yes… that’s the way it looked. A little … flat. All the nice material was gone. It took me some time that I manually had to bake the texture on a UV map that I would then be able to apply on the model. The result is the much more pleasing following:
As the color map was baked with the lighting information that Blender had, the asteroid only looks nice from the direction of the light, however the back does not get any shading at all. I could have added some more lights to improve the color map, however I thought I would try some shading fu and use normal mapping.
To do normal mapping I would need two things: a shader code for the fragment and vertex buffer and a normal map of the asteroid. Luckily there is also some shader code available from http://www.dhpoware.com so I only had to do a normal map for the asteroid. But also the creation of the normal map was much less of a hassle than expected. You only need to bake the normals in tangent space in Blender and off you go:
In these final versions the asteroids only have one colored textures and all the different shades of gray only come from the normal map combined with the shader. Notice the rough surface and the craters which actually are on quite flat surfaces. The model itself is the same as in the first in-game picture.
And now? Well, the asteroids do look very nice and creating now different kinds of asteroids and a space ship should not be too hard. But a bigger question would be whether I want to do this huge change of style, as the current 2D version of my game already looks very nice in my opinion.
But I am convinced that I will not only make one game so I will still have plenty of opportunities to use the code…
Oh and here is the model both in form of the .blend file for Blender and the exported .obj file along with material file, texture and normal map: