I am trying to use the glDrawElements() with glColorPointer() set to “color” elements/faces and not the individual vertices. Does anybody know if this is possible and if so, please help.
For example, I have an ASCII file that has a section with X, Y, Z coordinates and Elements/face section with point/nodal connectivity. such that:
Node1 X_coord Y_coord Z_coord
Node2 X_coord Y_coord Z_coord
Element1 Node1 Node2 Node3 Element1_color
Element2 Node3 Node4 Node5 Element2_color
I have been setting the GLfloat colors array using R, G, B but it looks like the colors are determined on the vertices/nodes and not for the element/face which is what I would like.
Any help/hints would be great.
All data specified using the gl*Pointer calls are per vertex. On GeForce 8 and better hw the functionality you seek can be implemented using geometry shaders however on any older hw you have to create new vertex for each unique combination of Node and element color. So the vertices might look something like:
X1, Y1, Z1, Element1_color
X2, Y2, Z2, Element1_color
X3, Y3, Z3, Element1_color
X3, Y3, Z3, Element2_color
X4, Y4, Z4, Element2_color
X5, Y5, Z5, Element2_color
One more question:
What about shared vertices? Each element/face with have some shared nodes/vertices, how is this typically handled with OpenGL using glColorPointers?
Thanks in advance.
For each vertex, you need to have a color and that’s not going to change.
Use index rendering (glDrawElements or glDrawRangeElements)
and you will be able to reuse vertices that are identical (same vertex and color)
Thank you, V-man.
Do you know of a link or some quick and simple example(s) of face/element coloring using index rendering? I am using glDrawElements() but am new, so any help would be great.