PDA

View Full Version : glColorPointer



Connection
12-05-2008, 12:12 PM
Hi,

I have a VertexArray, a ColorArray and an IndexArray for drawing a surface of triangles.

glColorPointer (3, GL_UNSIGNED_BYTE, sizeof (CGColor3ub), &colorArray[0][0]);
glVertexPointer (3, GL_FLOAT, sizeof (Vertex), &vertexArray[0][0]);
glDrawElements (GL_TRIANGLES, 3*getNumberOfTriangles(), GL_UNSIGNED_INT, triangleIndices);
With the ColorArray I want to color code the whole mesh, so that I can pick one triangle. To be more precise it's not about picking but about some collision calculation.

Let's say we have four points A, B, C, D. The first triangle is ABC with the same color for these points in the colorArray, let's say blue. Now when the second triangle BCD is drawn with the colorPointer pointing to red this triangle is in fact also colored blue.

So here is my question. What should I do to color code the triangle mesh. I guess I could add two points so that the triangles don't share points. So the better question would be if this colorpointer only sets the color of each vertex once instead of coloring it for each primitive. After writing this it seems to me that I gave myself the answer but I still hope that I am wrong about the colorPointer ;).

Komat
12-05-2008, 12:50 PM
All those arrays are indexed simultaneously to form input for the vertex processing. Vertex whose position is in 3th element of the vertex array will have color which is the 3th element of the color array. So if two triangles share the 3th vertex, they will have the same color for that vertex.

There is one situation where the result might be different. When the shading mode (glShadeModel) is set to GL_FLAT, entire triangle will have color taken from one from its vertices.