Game Development Reference
In-Depth Information
gl.glLoadIdentity();
gl.glOrthof(0, 320, 0, 480, 1, -1);
gl.glEnable(GL10. GL_TEXTURE_2D );
bobTexture.bind();
gl.glMatrixMode(GL10. GL_MODELVIEW );
for ( int i = 0; i < NUM_BOBS ; i++) {
gl.glLoadIdentity();
gl.glTranslatef(bobs[i].x, bobs[i].y, 0);
bobModel.draw(GL10. GL_TRIANGLES , 0, 6);
}
}
In the present() method, we clear the screen, set the projection matrix, enable texturing, and
bind the texture of Bob. The last couple of lines are responsible for actually rendering each Bob
instance. Since OpenGL ES remembers its states, we have to set the active matrix only once;
in this case, we are going to modify the model-view matrix in the rest of the code. We then loop
through all the Bob instances, set the model-view matrix to a translation matrix based on the
position of the current Bob instance, and render the model, which will be translated by the model
view-matrix automatically.
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
}
}
That's it. Best of all, we employed the MVC pattern we used in Mr. Nom again. It really lends
itself well to game programming. The logical side of Bob is completely decoupled from
his appearance, which is nice, as we can easily replace his appearance with something
more complex. Figure 7-20 shows the output of our little program after running it for a few
seconds.
Search WWH ::




Custom Search