Game Development Reference
In-Depth Information
above the RGB888 Bob rectangle. Note that the vertices of the first rectangle all have the color
(1,1,1,0.5f), while the vertices of the second rectangle all have the color (1,1,1,1).
@Override
public void
present(
float
deltaTime) {
GL10 gl = glGraphics.getGL();
gl.glViewport(0, 0, glGraphics.getWidth(), glGraphics.getHeight());
gl.glClearColor(1,0,0,1);
gl.glClear(GL10.
GL_COLOR_BUFFER_BIT
);
gl.glMatrixMode(GL10.
GL_PROJECTION
);
gl.glLoadIdentity();
gl.glOrthof(0, 320, 0, 480, 1, -1);
gl.glEnable(GL10.
GL_BLEND
);
gl.glBlendFunc(GL10.
GL_SRC_ALPHA
, GL10.
GL_ONE_MINUS_SRC_ALPHA
);
gl.glEnable(GL10.
GL_TEXTURE_2D
);
textureRgb.bind();
vertices.draw(GL10.
GL_TRIANGLES
, 0, 6 );
textureRgba.bind();
vertices.draw(GL10.
GL_TRIANGLES
, 6, 6 );
}
In our
present()
method, we clear the screen with red and set the projection matrix as we are
used to doing. Next, we enable alpha blending and set the correct blend equation. Finally, we
enable texture mapping and render the two rectangles. The first rectangle is rendered with
the RGB888 texture bound, and the second rectangle is rendered with the RGBA8888 texture
bound. We store both rectangles in the same
Vertices
instance and thus use offsets with the
vertices.draw()
methods. Figure
7-16
shows the output of this little gem.
Figure 7-16.
Bob, vertex color blended (bottom) and texture blended (top)