Game Development Reference
In-Depth Information
public void render(World world, float deltaTime) {
GL10 gl = glGraphics.getGL();
camera.getPosition().x = world.ship.position.x;
camera.getLookAt().x = world.ship.position.x;
camera.setMatrices(gl);
gl.glEnable(GL10. GL_DEPTH_TEST );
gl.glEnable(GL10. GL_TEXTURE_2D );
gl.glEnable(GL10. GL_LIGHTING );
gl.glEnable(GL10. GL_COLOR_MATERIAL );
ambientLight.enable(gl);
directionalLight.enable(gl, GL10. GL_LIGHT0 );
renderShip(gl, world.ship);
renderInvaders(gl, world.invaders, deltaTime);
gl.glDisable(GL10. GL_TEXTURE_2D );
renderShields(gl, world.shields);
renderShots(gl, world.shots);
gl.glDisable(GL10. GL_COLOR_MATERIAL );
gl.glDisable(GL10. GL_LIGHTING );
gl.glDisable(GL10. GL_DEPTH_TEST );
}
In the render() method, we start off by setting the camera's x coordinate to the ship's x
coordinate. Of course, we also set the x coordinate of the camera's look-at point accordingly.
This way, the camera will follow the ship. Once the position and look-at point are updated, we
can set the projection and model-view matrix via a call to LookAtCamera.setMatrices() .
Next, we set up all the states that we need for rendering. We'll need depth testing, texturing,
lighting, and the color material functionality so that we don't have to specify a material for the
objects via glMaterial() . The next two statements activate the ambient and directional light.
With these calls, we have everything set up and can start rendering the objects.
The first thing we render is the ship, via a call to renderShip() . Next, we render the invaders with
a call to renderInvaders() .
Since the shield blocks and shots don't need texturing, we simply disable that to save some
computations. Once texturing is turned off, we render the shots and shields via calls to
renderShots() and renderShields() .
Finally, we disable the other states we set so that we return a clean OpenGL ES state to whoever
called us.
private void renderShip(GL10 gl, Ship ship) {
if (ship.state == Ship. SHIP_EXPLODING ) {
gl.glDisable(GL10. GL_LIGHTING );
renderExplosion(gl, ship.position, ship.stateTime);
gl.glEnable(GL10. GL_LIGHTING );
} else {
Assets. shipTexture .bind();
Assets. shipModel .bind();
 
Search WWH ::




Custom Search