Game Development Reference
In-Depth Information
@Override
public void present( float deltaTime) {
GL10 gl = glGraphics.getGL();
gl.glViewport(0, 0, glGraphics.getWidth(), glGraphics.getHeight());
gl.glClear(GL10. GL_COLOR_BUFFER_BIT | GL10. GL_DEPTH_BUFFER_BIT );
gl.glMatrixMode(GL10. GL_PROJECTION );
gl.glLoadIdentity();
GLU. gluPerspective (gl, 67, glGraphics.getWidth()
/ ( float ) glGraphics.getHeight(), 0.1f, 10.0f);
gl.glMatrixMode(GL10. GL_MODELVIEW );
gl.glLoadIdentity();
gl.glTranslatef(0, -2, 0);
gl.glEnable(GL10. GL_DEPTH_TEST );
gl.glEnable(GL10. GL_TEXTURE_2D );
texture.bind();
cube.bind();
sun.render(gl);
cube.unbind();
gl.glDisable(GL10. GL_TEXTURE_2D );
gl.glDisable(GL10. GL_DEPTH_TEST );
}
// rest as in CubeScreen
Finally, we have the render() method. We start off with the usual setting of the viewport and
clearing of the framebuffer and depthbuffer. We also set up a perspective projection matrix and
load an identity matrix to the model-view matrix of OpenGL ES. The call to glTranslatef()
afterward is interesting: it will push our solar system down by 2 units on the y axis. This way, we
sort of look down on the system. This could be thought of as actually moving the camera up by
2 units on the y axis. This interpretation is actually the key to a proper camera system, which
we'll investigate in the next section, “A Simple Camera System�.
Once we have all the basics set up, we enable depth testing and texturing, bind the texture and
the cube mesh, and tell the sun to render itself. Since all the objects in the hierarchy use the
same texture and mesh, we only need to bind these once. This call will render the sun and all of
its children recursively, as outlined in the previous section. Finally, we disable depth testing and
texturing, just for fun. Figure 10-16 shows the output of our program.
Figure 10-16. Our crate solar system in action
 
Search WWH ::




Custom Search