Now, let's add a light to the scene and render the cube with it. To do this, we also need to define normal vectors for each face of the cube, which are used in the shader calculations.
If you derive Cube
from the one in Chapter 3, Cardboard Box, you may already have this code:
public static final float[] CUBE_NORMALS_FACES = new float[] { // Front face 0.0f, 0.0f, 1.0f, // Right face 1.0f, 0.0f, 0.0f, // Back face 0.0f, 0.0f, -1.0f, // Left face -1.0f, 0.0f, 0.0f, // Top face 0.0f, 1.0f, 0.0f, // Bottom face 0.0f, -1.0f, 0.0f, };
Now, add a buffers for the normals, like we have for colors and vertices, and allocate them:
public static FloatBuffer normalBuffer; ... public static void allocateBuffers(){ ... normalBuffer = allocateFloatBuffer( cubeFacesToArray(CUBE_NORMALS_FACES, 3) ); ...