Game Development Reference
In-Depth Information
There are no big surprises here, either. We just store the three components of the material and
provide setters and an enable() method, which sets the material.
OpenGL ES has one more trick up its sleeve when it comes to materials. Usually we wouldn't
use glMaterialfv() , but would instead choose something called color material . This means that
instead of the ambient and diffuse colors specified via glMaterialfv() , OpenGL ES will take the
vertex color of our models as the ambient and diffuse material color. To enable this nice feature,
we just have to call it:
gl.glEnable(GL10.GL_COLOR_MATERIAL);
We usually use this instead of a full-blown material class, as shown earlier, because ambient
and diffuse colors are often the same. Since we also don't use specular highlights in most of
our demos and games, we can get away with just enabling color materials and not using any
glMaterialfv() calls at all. The choice of using the Material class or color materials is totally up
to you.
Specifying Normals
For lighting to work in OpenGL ES, we have to specify vertex normals for each vertex of a
model. A vertex normal must be a unit-length vector that points in the (average) facing direction
of the surface(s) to which a vertex belongs. Figure 11-5 illustrates vertex normals for our cube.
Figure 11-5. Vertex normals for each vertex of our cube
A vertex normal is just another vertex attribute, like position or color. In order to upload vertex
normals, we have to modify our Vertices3 class one more time. To tell OpenGL ES where it
can find the normals for each vertex, we use the glNormalPointer() method, just like we used
the glVertexPointer() or glColorPointer() methods previously. Listing 11-6 shows our final
revised Vertices3 class.
 
Search WWH ::




Custom Search