Okay, I will write a more in depth tutorial later (probably with the GameModel class that I wrote) but I’m currently in Uganda, Africa (for about 6 mos) and net access is a bit spotty so here are a few hints to maybe get those of you who are having trouble started:
Again, my usual disclaimer: I am not an expert, I learned this as I wrote StarSmasher so I can’t promise anything I do is the best way to do it, and as always if you know a better way please let me/everyone know.
My draw script does the following (keep in mind this is part of a class so it refers to self and member data of the class but I think it should be fairly self explanatory):
//Check that this model isn't already loaded, we don't need to unnecessarily load it.
if (lastModel != self) {
//Loads the vertex array into OpenGL ES:
glVertexPointer(3, GL_FLOAT, 0, facesArray);
if (hasTexCoords) {
glBindTexture(GL_TEXTURE_2D, texture[0]); //texture[0] is an OpenGL texture id, loaded by my class during its init method.
glTexCoordPointer(2, GL_FLOAT, 0, textureCoordsArray);
}
lastModel = self;
}
//Draw the model:
glDrawArrays(GL_TRIANGLES, 0, facesCount*3);
The iPhone has an extremely limited amount of RAM (especially for doing 3D work). During development of the latest 1.1.0 release of StarSmasher I ran up against the glass ceiling on the RAM quite a lot. StarSmasher was only using about 20 MB of RAM at peak levels but this was enough for the app to receive low memory warnings from the OS. I don’t load that many textures, but the menu screen textures where full resolution 512×512 jpegs and I wasn’t doing any kind of unloading when they weren’t being used. Ultimately, this caused the app to crash after a couple of levels. I had written it this way initially to make the app feel snappier (because I figured 20 megs wasn’t that bad) and because I’m learning OpenGL as I go and didn’t fully understand the texture management.
Now I’ve implemented just in time texture loading for the menu screens that checks if the texture is loaded on draw and loads it if necessary. When a menu screen is exited (for instance by tapping the “done” button) I unload the texture (with glDeleteTextures). Below is the TextureLoader class I wrote to manage my textures.
Read the rest of this entry »
Below is a script I wrote to export models from blender into a *.h file that contains two static GLfloat arrays. It requires that the model be already triangulated in Blender (maybe later I’ll add code to go ahead and triangulate the mesh if it needs it… oh yeah, and to manually triangulate a mesh in Blender’s edit mode hit ‘Ctrl+T’) and that the mesh already have UV texture coordinates. Also, it only uses GL_TRIANGLES mode right now. Later I am going to update it to use GL_TRIANGLE_STRIPS instead of GL_TRIANGLES. Finally it doesn’t apply Object rotations and scale. You should apply them in Object Mode Transform->Clear/Apply->Apply Scale/Rotation (or Ctrl+A).
Read the rest of this entry »
I wrote this Asteroids clone in order to familiarize myself with Blender game engine python scripting. Because it was a learning experience I was tacking on new code as I figured things out, so you should not look at the overall design as a best practice by any means. Hopefully, though, the code will be useful to someone–I personally learned a lot writing it.
I appreciate any comments. Let me know what you think, what can be improved, and where I’ve done things stupidly; or if it happens to help you and you make some killer game as a result, I’d love to see that as well.
I’ll write a tutorial on how to build the game as time permits.
Files
spacerocks.blend (640.75 kB)
spacerocks.blend.zip (393.62 kB)