I am beginning to use vertex arrays and really need some help. I am trying to display a simple cube with data that looks like this:
//-------------------------------------------------------------
typedef struct MeinPointStruct {
GLdouble x, y, z;
} MeinPoint;
MeinPoint Quader_vertex[] = { { -10.0, -10.0, -10.0},
{ -10.0, 10.0, -10.0},
{ 10.0, 10.0, -10.0},
{ 10.0, -10.0, -10.0},
{ -10.0, -10.0, 10.0},
{ 10.0, -10.0, 10.0},
{ 10.0, 10.0, 10.0},
{ -10.0, 10.0, 10.0} };
GLubyte Quader_face[] = { 0,1,2,
2,3,0,
4,5,6,
6,7,4,
0,3,5,
5,4,0,
3,2,6,
6,5,3,
2,1,7,
7,6,2,
1,0,4,
4,7,1 };
…
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_DOUBLE, 0, Quader_vertex);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, Quader_face);
//----------------------------------------------------------------
As you can see I only select the first 6 points to be displayed to be able to see what the result looks like. Well, I really can see what I expect: The first face of the cube made out of two triangles. The problem is the light - or maybe I should say the normal vectors.
I thought that the normal vector (the one for all three point of the triangle) is given by the order of the vertices in one triangle: clockwise or counterclockwise…?
But when I look how the face is reflecting the light, that doesn’t seem to be true. Then I remembered glFrontFace() but it didn’t do anything. I also changed the order of the first three points to 0, 2, 1.
What am I doing wrong?
By the way: The reason why I try this is that I wanted to display some data exported with Crossroads from a 3DS file.
The original index array had a 4th column that was always -1.
Does anybody know why? I deleted this column because this doesn’t seemed to be any information…
And as Crossroads didn’t export any normal information I didn’t activated GL_NORMAL_ARRAY.
Is there someone who can help me or has a (hopefully simple) example of how to use vertex arrays in general or especially Crossroad exported meshes?