View Full Version : Coloring polygon faces
12-31-2006, 11:20 AM
I have an ASCII file with triangular polygons and corresponding X, Y, Z coordinates. Each of the polygons have a "color" associated with them. I am using glDrawElements for performance issues.
The problem is the proper coloring of the polygon faces. For example, If I have a file like the following:
Poly1 Coordinate_0 Coordinate_1 Coordinate_2 Red
Poly2 Coordinate_0 Coordinate_3 Coordinate_1 Blue
Coordinate_0 1.5 1.75 2.3
Coordinate_1 1.75 3.45 5.66
As you can see, Poly1 and Poly2 are sharing Coordinates 0, and 1 so there is an issue as to which one gets what color when coloring by vertices. Since I am sure that I am not the only one that has ran into this kind of problem before, I was wondering what is typically done to solve this kind of coloring problem?
Thanks in advance.
12-31-2006, 12:31 PM
Probably your best bet is to just duplicate the vertex. This is sometimes an issue with texture coordinates and other attributes that vary but share a position. Depending on your model and how many duplicates you have, your performance probably won't be hit badly at all, as long as your locality is good (i.e. keep recently used vertices as close together in the draw order as possible. This tends to make the most of the hardware's vertex cache).
01-01-2007, 03:07 AM
Since I am new to OpenGL, is using VBOs typical when the model being rendered is large and mouse interaction is needed or do most OpenGL applications take the performance hit and use the classical glBegin() ... glEnd() option?
I had used Display Lists which are good except they are immutable and can create memory thrashing.
Once again, thank you.
01-01-2007, 11:05 AM
VBO is the way to go.
01-02-2007, 05:22 AM
Yeah, VBOs are probably the way to go in this case, but DLs certainly have their uses; it really depends on the context.
If you have a large mesh that's subject to frequent modification, dynamic VBOs sound better to me because you have the ability to control the granularity of your update (glBufferSubData), and there's no need to recompile anything.
On the other hand, DLs are great for static objects coupled with certain state changes, since they give the driver an opportunity to optimize this stuff before hand; whereas with VBOs the driver's left in the dark. There always seems to be a trade off lurking somewhere ;)
01-02-2007, 06:25 AM
Thanks Falvious and satan,
I think that VBOs are probably the best way - I need both mouse interaction and speed since some of the meshes could be quite large.
01-02-2007, 10:42 AM
Another quick question (I hope it is not an overly stupid one but I am new to VBOs),
When I create duplicate nodes for the shared nodes, can I just append the new nodes to the color array pointer (for glColorPointer()) and the vertex pointer? Should I also create another polygon with the correspondingly new index? Can anybody provide a quick code snippet with this concept using VBOs - something very simple and quick?
Once again, thanks for all the help.
01-02-2007, 06:54 PM
Take a look this, vboSimple.zip (http://songho.ca/opengl/files/vboSimple.zip)
It draws a cube using VBO. And you can see the difference between VBO and Vertex Array implementation.
01-03-2007, 01:10 AM
Thank you songho. That code definately helped.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.