Game Development Reference
In-Depth Information
pointLight.disable(gl);
directionalLight.disable(gl);
gl.glDisable(GL10.
GL_TEXTURE_2D
);
gl.glDisable(GL10.
GL_DEPTH_TEST
);
}
Here it gets interesting. The first couple of lines are our boilerplate code for clearing the
colorbuffer and depthbuffer—enabling depth testing and setting the viewport.
Next, we set the projection matrix to a perspective projection matrix via
gluPerspective()
and also
use
gluLookAt()
for the model-view matrix, so that we have a camera setup as shown in Figure
11-6
.
Next, we enable lighting itself. At this point, we haven't defined any lights, so we do that in the
next couple of lines by calling the
enable()
methods of the lights as well as the material.
As usual, we also enable texturing and bind our crate texture. Finally, we call
glRotatef()
to
rotate our cube and then render its vertices with well-placed calls to the
Vertices3
instance.
To round off the method, we disable the point and directional lights (remember, the ambient light is a
global state) as well as texturing and depth testing. And that's all there is to lighting in OpenGL ES!
@Override
public void
pause() {
}
@Override
public void
dispose() {
}
}
The rest of the class is just empty; we don't have to do anything special in case of a pause.
Figure
11-7
shows the output of our example.
Figure 11-7.
Our scene from Figure
11-6
, rendered with OpenGL ES