I'm switching over to vertex arrays from display lists. When I draw the item using glDrawElements(), the shape draws fine (geometry wise), but the lighting is wierd. I've output the normals before the creation of the display list and the creation of the vertex array and they are both identical, so I'm thinking I'm doing something wrong with the vertex array's creation.
I store each unique vertex with its normal in a struct:
#pragma pack(1)
//other structs
struct vertex
{
vector norm; //vector is a class with only 3 floats as member variables
vector vert;
} *vertList;
//other structs
#pragma pack()
First real quick, it doesn't matter that there are other structs between the pragma calls, right? Each struct should be packed using pack(1).
Now, when I create my vertex arrays, I do the following:
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glNormalPointer(GL_FLOAT, 6*sizeof(float), &vertList[0].norm);
glVertexPointer(3, GL_FLOAT, 6*sizeof(float), &vertList[0].vert);
Does that look right? Now I make my call to glDrawElements() like this:
glDrawElements(GL_TRIANGLES, length, GL_UNSIGNED_INT, myArray);
myArray is simply the indexed list of vertices in the order they are to be drawn. Again, the object draws correctly with respect to its shape, it's only the lighting that is wrong, so I think it has something to do with the creation of the VA. Can anybody see anything I've done wrong?
Also, a quick question. Are the
start and
end parameters of glDrawRangeElements the min and max values of the
elements stored in the array? Or are they the min and max values of the
indices of the array?
So let's say we have this simple array:
int a[3] = {2, 5, 8};
Would the call to glDrawRangeElements look like this:
glDrawRangeElements(GL_TRIANGLES, 2, 8, 3, GL_UNSIGNED_INT, a);
or this:
glDrawRangeElements(GL_TRIANGLES, 0, 3, 3, GL_UNSIGNED_INT, a);
I would think it would be the first one (why would it need the second since it has a length, after all?), but the redbook (v1.2) is a little unclear as to what the parameters should be.
Thanks guys!
Without order nothing can exist - without chaos nothing can evolve.