在 iOS 上使用 OpenGL ES 模拟多边形点画
我想用简单的重复图案填充凹多边形。我已经可以正确绘制多边形,不幸的是我在填充它时遇到问题。在 OpenGL 中,我可以使用 POLYGON_STIPPLE 轻松完成此操作。然而,此功能在 OpenGL ES 中不可用。
我想我可能需要使用纹理而不是点画。然而,我无法弄清楚如何计算正确的纹理坐标,因为所有三角形的大小完全不同,但我仍然希望图案能够很好地彼此相邻。
是否有任何好的起点来解释如何使用重复纹理填充多边形,其中多边形比三角形或矩形稍微复杂一点?
I want to fill a concave polygon with a simple repeating pattern. I can already draw the polygon properly, unfortunately I am having problems with filling it. In OpenGL I could do this easily with POLYGON_STIPPLE. However this functionality is not available in OpenGL ES.
I figured that I probably need to use textures instead of stippling. However I cannot figure out how to calculate the correct texture coordinates as all the triangles are of completely different sizes, but I still want the pattern to fit well right next to each other.
Are there any good starting points that explain how to fill polygons with a repeating texture, where the polygon is a little more complex than one triangle or rectangle?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
计算纹理坐标并不像我想象的那么难。用图案填充多边形可以这样完成:
设置纹理参数,以便纹理重复自身。这将产生这样的效果:对于每个大于 1 的坐标,纹理将再次重复。
计算纹理坐标。每个顶点坐标c对应一个纹理坐标,计算如下: (cx/texture.width, cy/texture.height)
Calculating the texture coordinates is not as hard as I thought. Filling the polygon with a pattern can be done like this:
Set texture parameter so that texture repeats itself. This will have the effect, that for every coordinate bigger than 1 the texture will just repeat all over again.
Calculate texture coordinates. Each vertix coordinate c corresponds to a texture coordinate calculated like this: (c.x/texture.width, c.y/texture.height)