Jump to content


OpenGL VBO coloring polygon faces


4 replies to this topic

#1 rhhaney145

    New Member

  • Members
  • PipPip
  • 15 posts

Posted 03 January 2007 - 02:56 AM

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.

#2 TheNut

    Senior Member

  • Moderators
  • 1718 posts
  • LocationCyberspace

Posted 03 January 2007 - 03:45 AM

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)
http://www.nutty.ca - Being a nut has its advantages.

#3 rhhaney145

    New Member

  • Members
  • PipPip
  • 15 posts

Posted 03 January 2007 - 04:03 AM

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?

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 5344 posts
  • LocationSanta Clara, CA

Posted 03 January 2007 - 05:31 AM

Yes, that's exactly what you have to do.
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 rhhaney145

    New Member

  • Members
  • PipPip
  • 15 posts

Posted 03 January 2007 - 09:55 AM

Thanks to everybody for all the great help.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users