tags:

views:

487

answers:

1

want 20k+ 2D polygons to be rendered in opengl with outline & fill

some polygons are concave

is it possible to do this using shaders?

thx!

+2  A: 

You don't need shaders for this:

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //Fill
glDrawElements(...);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); //Outline
glDrawElements(...);

If the polygons are concave you'll have to tesselate them, either manually or using the gl utility library, glu. Look at gluNewTess. If you decide to tesselate the polygons yourself you'll have to remember to set the correct edge flags so that the interior edges of the tesselation aren't rendered, see glEdgeFlagPointer.

EDIT: I found the following link on how to use the stencil buffer to render concave polygons.

Andreas Brinck
if some polygons are concave?
madcat
@madcat See updated answer
Andreas Brinck
thanks! will try. but still, tessellation has to be done on CPU, not using a shader?
madcat
@madcat Generally yes, it may be possible to do on the GPU in future versions of geometry shaders but I don't *think* it's possible right now. However, I found an interesting way of rendering concave polygons using the stencil buffer, see update.
Andreas Brinck
The stencil method is somewhat better explained here: http://fly.srk.fer.hr/~unreal/theredbook/chapter13.html (search for concave). It involves drawing the polygon as a triangle fan twice, first to generate the stencil buffer, second to draw where the stencil was set.
Bahbar