Game Development Reference
In-Depth Information
public
TestScreen(Game game) {
super
(game);
glGraphics = ((GLGame) game).getGLGraphics();
}
@Override
public void
present(
float
deltaTime) {
GL10 gl = glGraphics.getGL();
gl.glClearColor(rand.nextFloat(), rand.nextFloat(),
rand.nextFloat(), 1);
gl.glClear(GL10.
GL_COLOR_BUFFER_BIT
);
}
@Override
public void
update(
float
deltaTime) {
}
@Override
public void
pause() {
}
@Override
public void
resume() {
}
@Override
public void
dispose() {
}
}
}
This is the same program as our last example, except that we now derive from
GLGame
instead
of
Activity
, and we provide a
Screen
implementation instead of a
GLSurfaceView.Renderer
implementation.
In the following examples, we'll only look at the relevant parts of each example's
Screen
implementation. The overall structure of our examples will stay the same. Of course, we have to
add the example
GLGame
implementations to our starter
Activity
, as well as to the manifest file.
With that out of our way, let's render our first triangle.
Look Mom, I Got a Red Triangle!
You already learned that OpenGL ES needs a couple of things set before we can tell it to draw
some geometry. The two things about which we are most concerned are the projection matrix
(and with it our view frustum) and the viewport, which governs the size of our output image and
the position of our rendering output in the framebuffer.