I am new to OpenGL VBOs and am having some difficulty coloring shared vertices - I really need to color by polygon face. For example I have a file of triangles that are connected and as such will have some shared vertices. Example file:
Tri1 vert1 vert2 vert3 color_red
Tri2 vert3 vert2 vert4 color_blue
vert1 X-coord Y-coord Z-coord
vert2 X-coord Y-coord Z-coord
So, the "shared" vertices are neither Red or Blue but the faces of the polygons are definately Red or Blue since the color is actually associated with the polygons and not the vertices. I know that I should make copies of the shared vertices to properly display the colors using the glDrawElements() and glColorPointer() but am unsure of the correct execution.
Can I just append the newly duplicated, shared nodes to the already existing Color and vertex arrays? Do I also need to append a new indice for the array being passed to the glDrawElements()? It seems that I should also have a duplicate polygon indice to render the polygon with the duplicate node also but I don't know if this is the case.
Any hints/help or some simple and quick pseudo-code would be great. Like I said, I am a newbie with regards to OpenGL VBOs.
Thanks in advance.
This is the same problem for models where multiple vertices exist in order to support multiple texture coordinates or normals. It screws everything up when one attempts to weld them together to improve performance. In your case, you want to unweld your vertices. Instead of sharing the same vertex indicies, create new ones with your specified colour
tri1.vertex = (x1, y, z) uses (r1, g1, b1)
tri2.vertex = (x2, y, z) uses (r2, g1, b1)
tri1.vertex = (x, y, z) uses (r1, g1, b1)
tri2.vertex = (a, b, c) uses (r2, g2, b2)
Since I am dealing with a set of finite elements (the triangles) that are all connected, I should essentially take them all apart into separate Triangles? For example (ASCII File):
TRI_1 vert1 vert2 vert3 RED_COLOR
TRI_2 vert3 vert4 vert5 BLUE_COLOR
vert1 1.0 1.0 1.0
vert2 0.5 1.5 0.5
vert3 1.5 1.0 1.0
vert4 2.0 0.5 1.5
vert5 2.5 1.0 2.0
Given that vert3 is shared by BOTH TRI_1 and TRI_2 (in one case it is RED and the other case it is BLUE), vert3 should be split into two different vertices such as vert3 (1.5 1.0 1.0) and vert3_cp (1.5 1.0 1.0) and give one the color RED and the other BLUE?
Yes, that's exactly what you have to do.
Thanks to everybody for all the great help.