I have started looking into lighting, and created a simple cube for
some experimentation, but cannot get a normal array to work. If I do
not enable GL_NORMAL_ARRAY and instead “manually” call glNormal3f with
my normals, it works fine. I built the cube walls into vertex arrays,
actually a FloatBuffer array with 6 elements for each wall, which
render fine. And I build the six normal arrays with the following
function
public static FloatBuffer [] buildCubeNormals()
{
// builds normals in same side order as buildRectSolid
FloatBuffer [] normals = new FloatBuffer[6];
for (int i = 0; i < 6; i++)
normals[i] = BufferUtils.newFloatBuffer(3);
normals[0].put(new float[]{0.0f, 0.0f, 1.0f});
normals[1].put(new float[]{1.0f, 0.0f, 0.0f});
normals[2].put(new float[]{-1.0f, 0.0f, 0.0f});
normals[3].put(new float[]{0.0f, 0.0f, -1.0f});
normals[4].put(new float[]{0.0f, 1.0f, 0.0f});
normals[5].put(new float[]{0.0f, -1.0f, 0.0f});
return normals;
}
But this does not work. Here is the segment of my display code
gl.glEnableClientState(GL.GL_VERTEX_ARRAY | GL.GL_NORMAL_ARRAY);
for (int i = 0; i < 6; i++)
{
gl.glNormalPointer(GL.GL_FLOAT, 0, cubeNormals[i]);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, cube[i]);
gl.glDrawArrays(GL.GL_POLYGON, 0, 4);
}
gl.glDisableClientState(GL.GL_VERTEX_ARRAY | GL.GL_NORMAL_ARRAY);
As I said, if I do not enable GL_NORMAL_ARRAY, and instead call
glNormal3f intead of glNormalPointer, giving it the correct
coordinates for each of the six sides, it works fine. I even tried
putting the same normal points into the arrays four times, thinking it
might want a normal for each vertex instead of for each polygon. And
still nothing. I would like to start using interleaved arrays, but
obviously need to overcome my ignorance of what is going on here.
Please help, my brains are hurting.