OpenGL VBO coloring polygon faces

3b585a05bb395f406d0a5d980f9dd954
0
rhhaney145 101 Jan 03, 2007 at 02:56

Please Help,

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:

TRIANGLES:
Tri1 vert1 vert2 vert3 color_red
Tri2 vert3 vert2 vert4 color_blue

VERTICES:
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.

4 Replies

Please log in or register to post a reply.

6837d514b487de395be51432d9cdd078
0
TheNut 179 Jan 03, 2007 at 03:45

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)

now becomes

tri1.vertex = (x, y, z) uses (r1, g1, b1)
tri2.vertex = (a, b, c) uses (r2, g2, b2)

3b585a05bb395f406d0a5d980f9dd954
0
rhhaney145 101 Jan 03, 2007 at 04:03

Thank you.

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):

TRIANGLES:
TRI_1 vert1 vert2 vert3 RED_COLOR
TRI_2 vert3 vert4 vert5 BLUE_COLOR
VERTICES:
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?

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Jan 03, 2007 at 05:31

Yes, that’s exactly what you have to do.

3b585a05bb395f406d0a5d980f9dd954
0
rhhaney145 101 Jan 03, 2007 at 09:55

Thanks to everybody for all the great help.