views:

121

answers:

1

I'm drawing 2D, concave, sometimes multicontoured, sometimes self intersecting polygons with OpenGL. Here is a sample: alt text

Right now, I take the points which if connected would result in the polygon's outline. Then I put these into the GLUTesselator where triangles come out. I then make texture coordinates and texture the polygon.

The absolute slowest component is the tessellation / triangulation. Given that I just need to draw these as you see, what are faster alternatives to triangulating? Could I possibly find a painting algorithm that would set the pixel appropriately?

Thanks

+1  A: 

First a simpler problem: suppose you just wanted to use one color. You could start with the list of outlines, then scan the whole window by row and column: whenever you crossed a boundary, you would increment or decrement (depending on the sense of the crossing) a counter how_many_outlines_am_I_inside. When it's zero, paint the pixel white, otherwise paint it green (and I guess black for the boundary itself). This will handle self-intersecting curves correctly.

Now for the shades. Judging by your example, shading is uniform vertically, but changes horizontally, scaled to the full width of the outline. So instead of a simple counter, you'll need a stack (I recommend stl::list) of outlines, so that you can keep track of which outline (of the ones you're inside) is uppermost, so that you can calculate what fraction of the distance you've covered from xmin to xmax. Finally for the translucency (as with the star partly visible through the rectangle): you'll have to decide on the rules yourself, I can't infer them by eyeball, but the stack should make it easy to implement.

Want some help with the C++ code?

Beta
Well I did some more searching and found that there is a technique involving the stencil buffer. I will try this and if it's ot what I'm looking for I'll get back to you :)
Milo
I think he's drawing one polygon at a time -- I don't see the need for a stack.
Tom Sirgedas
@Tom Sirgedas: my method involves coloring one pixel at a time, so it needs a stack. Come to think of it, there some interesting optimization tricks one could try...
Beta