my vertex data (position and norms) is currently stored in a GL_ARRAY_BUFFER_ARB. the vertex ids (3 ids for one triangle) are hold in a GL_ELEMENT_ARRAY_BUFFER_ARB. The scene is drawn with glDrawElements().
I now want to draw whole triangles (not single vertices!) in different RGBA colors. I’ve read about glColorPointer() but this seems to work only for coloring single vertices. Since the triangles share vertices this isn’t possible for me.
The scene I’m drawing is quite large, so I’d like to stick to my vertex buffer objects if possible.
Maybe someone here can suggest a solution. That would be really nice.
Since the triangles share vertices this isn’t possible for me.
No, triangles do not share vertices. A vertex is a collection of data which includes the position, but is not only the position. Triangles that use the same vertex positions but different vertex colors do not share vertices.
Therefore, you must break up your position list, such that each triangle uses its own vertex positions (not shared with other vertices), which can be paired up with different vertex colors.
That won’t help. Because each triangle needs to have its own color. We’re talking about vertex attribute data, not post-transform shader data.
In order for flat shading to work as you suggest, you would have to be very, very careful about which colors you assign which triangles. Triangle strips are right out the window, and an optimized list would be difficult if not impossible to generate.