Game Development Reference
In-Depth Information
and texture outside the
for
loop, we have to unbind and rebind them before we can render an
explosion instead of an invader.
private void
renderShields(GL10 gl, List<Shield> shields) {
gl.glEnable(GL10.
GL_BLEND
);
gl.glBlendFunc(GL10.
GL_SRC_ALPHA
, GL10.
GL_ONE_MINUS_SRC_ALPHA
);
gl.glColor4f(0, 0, 1, 0.4f);
Assets.
shieldModel
.bind();
int
len = shields.size();
for
(
int
i = 0; i < len; i++) {
Shield shield = shields.get(i);
gl.glPushMatrix();
gl.glTranslatef(shield.position.x, shield.position.y,
shield.position.z);
Assets.
shieldModel
.draw(GL10.
GL_TRIANGLES
, 0,
Assets.
shieldModel
.getNumVertices());
gl.glPopMatrix();
}
Assets.
shieldModel
.unbind();
gl.glColor4f(1, 1, 1, 1f);
gl.glDisable(GL10.
GL_BLEND
);
}
The
renderShields()
method renders the shield blocks. We apply the same principle as in the
case of rendering invaders. We only bind the model once. Since we have no texture, we don't
need to bind one. However, we need to enable blending. We set the global vertex color to blue,
with the alpha component set to 0.4. This will make the shield blocks a little transparent.
private void
renderShots(GL10 gl, List<Shot> shots) {
gl.glColor4f(1, 1, 0, 1);
Assets.
shotModel
.bind();
int
len = shots.size();
for
(
int
i = 0; i < len; i++) {
Shot shot = shots.get(i);
gl.glPushMatrix();
gl.glTranslatef(shot.position.x, shot.position.y, shot.position.z);
Assets.
shotModel
.draw(GL10.
GL_TRIANGLES
, 0,
Assets.
shotModel
.getNumVertices());
gl.glPopMatrix();
}
Assets.
shotModel
.unbind();
gl.glColor4f(1, 1, 1, 1);
}
Rendering the shots in
renderShots()
is the same as rendering the shields, except that we don't
use blending and we use a different vertex color (yellow).
private void
renderExplosion(GL10 gl, Vector3 position,
float
stateTime) {
TextureRegion frame = Assets.
explosionAnim
.getKeyFrame(stateTime,
Animation.
ANIMATION_NONLOOPING
);