Exclude a 2D polygon from a 2D polygon

Dear all,

Please tell me if you know a good algorithm for excluding a 2D polygon from a 2D polygon. I would like to appreciate your help

Depending upon your requirements, I can make two suggestions.

  1. To draw polygon A with polygon B subtracted, first draw polygon B with the depth and color buffers disabled but with the stencil buffer enabled and to write a value of 1 to the stencil buffer. Then draw polygon A where the stencil buffer is not 1. Make sure the stencil buffer is cleared to zero each frame. If you need to reuse the stencil buffer for drawing other geometry, you need to set the stencil buffer back to zero by redrawing polygon B with a stencil value of zero.

  2. Use the gluTess* functions to create a polygon that is the difference of the two polygons.

Thanks for your help