pyopengl 如何给凹多边形着色

发布于 2025-01-18 06:38:20 字数 179 浏览 4 评论 0原文

pyopengl如何颜色凹入多边形,像这样的图形,填充颜色时,我总是填充凹面的位置。我希望我可以根据图的轮廓填充颜色“在此处输入图像描述”

在填充颜色时,我总是填充凹面平坦。我希望我可以根据图的轮廓填充颜色

pyopengl How to color concave polygons,graphics like this,When filling the color, I always fill the concave place flat. I hope I can fill the color according to the outline of the figureenter image description here

When filling the color, I always fill the concave place flat. I hope I can fill the color according to the outline of the figure

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃→可爱长大的 2025-01-25 06:38:20

不要画多边形。绘制许多三角形,将它们组合起来形成多边形。

当然,您可以用任何您喜欢的方式生成三角形,例如使用铅笔、纸和尺子并输入坐标。

对于此多边形,您可能会发现 GL_TRIANGLE_FAN 很有用,因为不需要太多更改:在多边形中间的顶点开头添加一个新顶点,以便每个其他顶点都可以看到您添加的一个。 OpenGL将生成从中心点向外辐射到所有边缘顶点的三角形。这对于像你这样的“大部分是凸的”多边形来说很方便。三角形将如下所示:

与问题中的多边形相同,但线条从中间的新顶点向外辐射到每个顶点

如果多边形不是“大部分凸”,您很可能需要使用GL_TRIANGLES 允许您按照自己的喜好将其分割。


另一种选择是绘制一个 alpha 纹理的四边形,并打开 alpha 测试。 GPU 将绘制一个正方形并忽略 alpha 为 0 的角落中的像素。由于您的多边形“几乎是一个正方形”,因此计算这些像素并忽略它们所浪费的工作可能比处理更多像素的额外工作要少三角形。没有办法完美地预测这一点。使用这种方法,角形状将是基于像素的而不是基于三角形的,因此如果放大它会变得块状。

Don't draw a polygon. Draw many triangles, which combine to make the polygon.

Of course, you can generate the triangles in any way you like, such as with pencil and paper and a ruler and typing in the coordinates.

For this polygon, you might find GL_TRIANGLE_FAN useful, since not much change is needed: add one new vertex at the beginning of the vertices, in the middle of the polygon, so that every other vertex can see the one you added. OpenGL will generate triangles radiating outwards from the central point to all the edge vertices. This is convenient for polygons like yours which are "mostly convex". The triangles will look like this:

Same polygon as in the question, but with lines radiating outwards to every vertex from a new vertex in the middle

If the polygon wasn't "mostly convex", you would most likely need to use GL_TRIANGLES which allows you to split it up however you like.


Another option is to draw an alpha-textured quad, with alpha test turned on. The GPU will draw a square and ignore the pixels in the corners where the alpha is 0. Since your polygon is "almost a square" the wasted work to calculate those pixels and ignoring them could be less than the extra work to process a bunch more triangles. There's no way to perfectly predict that. With this approach, the corner shape would be pixel-based instead of triangle-based, so it would get blocky if you zoomed in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文