Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Triangulation is he obvious answer, but it's hard to write a solid triangulator. Unless you have two month time to waste don't even try it.</p> <p>There are a couple of codes that may help you:</p> <p>The GPC Library. Very easy to use, but you may not like it's license: </p> <p><a href="http://www.cs.man.ac.uk/~toby/alan/software/gpc.html" rel="nofollow noreferrer">http://www.cs.man.ac.uk/~toby/alan/software/gpc.html</a></p> <p>There is also triangle:</p> <p><a href="http://www.cs.cmu.edu/~quake/triangle.html" rel="nofollow noreferrer">http://www.cs.cmu.edu/~quake/triangle.html</a></p> <p>And FIST:</p> <p><a href="http://www.cosy.sbg.ac.at/~held/projects/triang/triang.html" rel="nofollow noreferrer">http://www.cosy.sbg.ac.at/~held/projects/triang/triang.html</a></p> <p>Another (and my prefered) option would be to use the GLU tesselator. You can load and use the GLU library from DirectX programs just fine. It does not need an OpenGL context to use it and it's pre-installed on all windows machines. If you want source you can lift off the triangulation code from the SGI reference implementation. I did that once and it took me just a couple of hours.</p> <p>So far for triangulation. There is a different way as well: You can use stencil tricks.</p> <p>The general algorithm goes like this:</p> <ol> <li><p>Disable color- and depth writes. Enable stencil writes and setup your stencil buffer that it will invert the current stencil value. One bit of stencil is sufficient. Oh - your stencil buffer should be cleared as well.</p></li> <li><p>Pick a random point on the screen. Any will do. Call this point your Anchor.</p></li> <li><p>For each edge of your polygon build a triangle from the two vertices that build the edge and your anchor. Draw that triangle. </p></li> <li><p>Once you've drawn all these triangles, turn off stencil write, turn on stencil test and color-write and draw a fullscreen quad in your color of choice. This will fill just the pixels inside your convex polygon.</p></li> </ol> <p>It's a good idea to place the anchor into the middle of the polygon and just draw a rectangle as large as the boundary box of your polygon. That saves a bit of fillrate.</p> <p>Btw - the stencil technique works for self-intersecting polygons as well.</p> <p>Hope it helps, Nils</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload