Drawing outline of intersecting circles

风格不统一 提交于 2019-12-05 01:45:51

First, imagine the background was not there. I'm pretty sure you'd know how to do it, draw each circle then draw their insides (as in a filled circle) to remove the arcs that are inside.

Now to do the same over an image, you could do either of these things. One thing you can do is to disable writing on the color buffer, do that procedure and change the stencil buffer. Then enable writing on the color buffer and draw a whole screen rectangle which consequently fills the pixels you have marked in the stencil buffer.

The stencil buffer may not be usable to you however for a couple of reasons, such as you are using it for something else. In this case, an alternative would be to do the same thing, but instead of rendering in the stencil buffer, you render in a texture. Then bind that texture and draw a rectangle on the screen.

I'm quite certain you could achieve this with the accumulation buffer too, but I have never used it so I can't really tell (if anyone knows about that, please edit my answer and tell us how)

Two passes:

  1. Draw all your circle outlines via GL_LINES or GL_LINE_LOOP. Make sure you set your glLineWidth() to 3 or greater.
  2. Draw filled circles (GL_TRIANGLE_STRIP can be useful) with your "background" color and the same radius as the circles from step 1.

The filled circles in step 2 will overwrite all the outline pixels from step 1 but only where they overlap. That leaves you with non-overlapping outlines intact.

If you want a wider range of outline widths (i.e., greater than the ~10 that most OpenGL implementations allow glLineWidth()) you should reuse the filled-circle renderer from step 2 in step 1 except with a larger radius.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!