pyopengl 如何给凹多边形着色
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 figure
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要画多边形。绘制许多三角形,将它们组合起来形成多边形。
当然,您可以用任何您喜欢的方式生成三角形,例如使用铅笔、纸和尺子并输入坐标。
对于此多边形,您可能会发现 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: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.