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 = {

EGL10.EGL_DEPTH_SIZE, 0, EGL10.EGL_N0NE

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);

gl.glMatrixMode(GLl0.GL_PROJECTION);

gl.glLoadIdentity();

public void drawFrame(GLl0 gl) {

gl.glDisable(GLl0.GL_DITHER);

gl.glClear(GLl0.GL_COLOR_BUFFER_BIT | GLl0.GL_DEPTH_BUFFER_BIT);

gl.glMatrixMode(GLl0.GL_MODELVIEW);

gl.glLoadIdentity();

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