Game Development Reference
In-Depth Information
Figure 11-6.
Our first lit scene
As with all of our examples, we create a class called
LightTest
, which extends
GLGame
as usual.
It returns a new
LightScreen
instance from its
getStartScreen()
method. The
LightScreen
class
extends
GLScreen
, and this is shown in Listing 11-7.
Listing 11-7. Excerpt from LightTest.java; Lighting with OpenGL ES
class
LightScreen
extends
GLScreen {
float
angle;
Vertices3 cube;
Texture texture;
AmbientLight ambientLight;
PointLight pointLight;
DirectionalLight directionalLight;
Material material;
We start off with a couple of members. The
angle
member stores the current rotation of the cube
around the y axis. The
Vertices3
member stores the vertices of the cube model, which we are
going to define in a bit. In addition, we store
AmbientLight
,
PointLight
,
DirectionalLight
, and
Material
instances.
public
LightScreen(Game game) {
super
(game);
cube = createCube();
texture =
new
Texture(glGame, "crate.png");
ambientLight =
new
AmbientLight();
ambientLight.setColor(0, 0.2f, 0, 1);
pointLight =
new
PointLight();
pointLight.setDiffuse(1, 0, 0, 1);
pointLight.setPosition(3, 3, 0);
directionalLight =
new
DirectionalLight();