glColorPointer & glDrawElements

Hi everyone.
I’ve been experimented many problems with lists in OpenGL.
I got for pointers, one for vertexes, other one for faces, other one for normals and other one for vertex colors.

I actually do this (in Delphi).

DrawingList := glGenLists (1);

glNewList (DrawingList, GL_COMPILE);

glColorPointer (4, GL_FLOAT, 0, @PColorList);
glEnableClientState (GL_COLOR_ARRAY);

glVertexPointer (3, GL_FLOAT, 0, @VertexList);
glEnableClientState (GL_VERTEX_ARRAY);

glNormalPointer (GL_FLOAT, 0, @NormalList);
glEnableClientState (GL_NORMAL_ARRAY);

glDrawElements (GL_TRIANGLES, 36, GL_UNSIGNED_INT, @FaceList);

glEndList;

This code draw a cube with triangles. I have no problems with faces, vertexes or normals. My cube appears correctly. But glVertexPointer don’t paint my vertexes as I want. I tryed all possible combinations of colors, pointers or else. But I can’t find a way to paint my cube faces as I want. Do someone know why I can do this ???

Thanx.

Hi,
You can’t include gl*Pointer in display lists.

[This message has been edited by Michail Bespalov (edited 05-26-2001).]

Allow me to add to what Michail said.

When you compile vertex array functions into a display list, it draws those vertex positions, normals, colors, and whatever else you specify as an active array out at the moment when glDrawElements is called (or perhaps when glEndList is called, but probably not).

Basically, if you change the contents of the array (the actual memory the pointers point to) after you compile it, you will not get the changed data in the display list. So, the color values you get will be from the color values specified at the moment you called glDrawElements in the compilation.

Another thing related you your color problem. I’m not sure how lighting and vertex colors work with vertex arrays, but I’ll assume it works the same way as immediate mode. You need to turn on glColorMaterial in order for your per-vertex colors to actually be used in the lighting calculations. Otherwise, the color will follow the color value set with glMaterial calls.

Hi. I understand your idea. I also enable glColorMaterial for the correct visualization of the colors, but thats not my problem. I have no problem with lights or normals.

When I call glDrawElements, all my pointers are filled with the correct data, vertexes, normals and faces are rendered as I want. But the function glColorPointer seems not to take the information of the pointer and it’s only paint the front face of my cube with red and the rare face with blue. The others faces are painted with a gradient of red and blue. In a few words, it’s ignore all the pointer and I don’t know why. I will include the definition of my pointers. Maybe this helps to understand the problem.

FaceList : Array [0…35] Of GLInt =
(0, 2, 3, 0, 1, 2, // Face 0 - front
0, 3, 5, 0, 5, 4, // Face 1 - right
4, 5, 6, 4, 6, 7,
7, 6, 2, 7, 2, 1,
1, 0, 7, 0, 4, 7,
3, 2, 6, 6, 5, 3);

VertexList : Array [0…23] Of GLFloat =
( 1.0, 1.0, 1.0, { Vertex 0 }
-1.0, 1.0, 1.0, { Vertex 1 }
-1.0, -1.0, 1.0, { Vertex 2 }
1.0, -1.0, 1.0, { Vertex 3 }
1.0, 1.0, -1.0, { Vertex 4 }
1.0, -1.0, -1.0, { Vertex 5 }
-1.0, -1.0, -1.0, { Vertex 6 }
-1.0, 1.0, -1.0); { Vertex 7 }

NormalList : Array [0…17] Of GLFloat =
( 0.0, 0.0, 1.0, { Face 0 }
1.0, 0.0, 0.0, { Face 1 }
-1.0, 0.0, 0.0, { Face 2 }
0.0, 1.0, 0.0, { Face 3 }
0.0, -1.0, 0.0, { Face 4 }
0.0, 0.0, -1.0); { Face 5 }

PColorList : Array [0…95] Of GLFloat =
(1.0, 0.0, 0.0, 1.0,
1.0, 0.0, 0.0, 1.0,
1.0, 0.0, 0.0, 1.0,
1.0, 0.0, 0.0, 1.0,
1.0, 0.0, 1.0, 1.0,
1.0, 0.0, 1.0, 1.0,
1.0, 0.0, 1.0, 1.0,
1.0, 0.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 0.0, 1.0, 1.0,
1.0, 0.0, 1.0, 1.0,
1.0, 0.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0);

It don’t matter haw many elements I put or how many colors y change. glColorArray ignore it all. Thanx for answer. Bye.

>>When I call glDrawElements, all my pointers are filled with the correct data, vertexes, normals and faces are rendered as I want. But the function glColorPointer<<

as others have said u can’t rely on points in lists even if they are filled with correct data. check the red book for further info

also i might add glEnableClientState(…) is also not allowed

[This message has been edited by zed (edited 05-26-2001).]

The vertex, normal and color arrays all need to have the same number of elements, where “element” is typically x/y/z or nx/ny/nz or cr/cg/cb (depeneding on your call to XxxPointer.