PDA

View Full Version : glColorPointer and colors for whole triangle



kraeste
05-22-2011, 08:00 AM
hello there!

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.

Cheers!

V-man
05-22-2011, 09:38 AM
You would have to use glColor4f or one of the other glColor and then call glDrawElements for every single triangle.

As for glColorPointer, it is in the FAQ
http://www.opengl.org/wiki/FAQ#Multi_indexed_rendering

Alfonse Reinheart
05-22-2011, 01:08 PM
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.

Xmas
05-23-2011, 02:40 AM
Sounds like flat shading to me.
glShadeModel(GL_FLAT); (http://www.opengl.org/sdk/docs/man/xhtml/glShadeModel.xml)

Alfonse Reinheart
05-23-2011, 02:51 AM
Sounds like flat shading to me.

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.