Abstract Rendererjava

The way you bind and unbind the EGL context to the surface and the way you set the viewport, camera, and so on could be common to a number of scenarios. With this in mind, we have abstracted this functionality out further by creating an abstract class to deal with these variations (see Listing 10-11).

Listing 10-11. The AbstractRenderer Class //filename: AbstractRenderer.java public abstract class AbstractRenderer implements Renderer {

public int[] getConfigSpec() { int[] configSpec = {


return configSpec;

public void surfaceCreated(GL10 gl) { gl.glDisable(GLl0.GL_DITHER); gl.glHint(GLl0.GL_PERSPECTIVE_CORRECTIONJHINT,

GL10.GL_FASTEST); gl.glClearColor(.5f, .5f, .5f, l); gl.glShadeModel(GLl0.GL_SMOOTH); gl.glEnable(GLl0.GL_DEPTH_TEST);

public void sizeChanged(GLl0 gl, int w, int h) { gl.glViewport(0, 0, w, h);



public void drawFrame(GLl0 gl) {





GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

gl.glEnableClientState(GLl0.GL_VERTEX_ARRAY); draw(gl);

protected abstract void draw(GLl0 gl);

Based on our explanation of the camera symbolism, you should be able to understand this code, especially how the gluLookAt, glFrustum, and glViewport methods are used.

The aforementioned six classes complete the test harness. The next two classes exercise the test harness by drawing a simple triangle and a few variations of it. You will need at least one of these classes to be able to see something on the emulator.

0 0

Post a comment