normal array issue

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.

From how i understand it your code will draw make six quads with the correct normals but with

cube[0]cube[1]cube[2]cube[3]
cube[1]cube[2]cube[3]cube[4]
cube[2]cube[3]cube[4]cube[5]
cube[3]cube[4]cube[5]cube[6]
cube[4]cube[5]cube[6]cube[7]
cube[5]cube[6]cube[7]cube[8]

for each quads. You can try to put the vertex entries in such an order that when being drawn like this it will have the correct values but i don’t know whether such an ordering is actually possible.

Therefore if your cube array contains 24 entries i suggest you put each 4 vertices of each quads after another and do

gl.glVertexPointer(3, GL.GL_FLOAT, 0, cube[4*i]); 

But be careful i am assuming that gl.glDrawArrays draws only one quad, which can actually be wrong. I have in mind that this method actually takes each group of n entries (here 4) and create a polygon with it repeatedly. Meaning that it would take 4 entries of your normal array too.

So i suggest to see the documentaiton of it to check about that. If draw only one quad then think of my suggestion. Otherwise you have to create an array of normals of the same size of your vertex array. (Meaning that you will have obviously repeated entries).

Hope this can help