OpenGL ES - 如何绘制填充多边形?
我尝试在堆栈上进行谷歌搜索和搜索,但没有找到任何东西:-(
( 映射不规则形状或其他多边形(卡通、精灵)到 OpenGL ES 中的三角形 )
我想在 iPad 上的 OpenGL ES 中绘制填充多边形(2D,不需要 3D) (我是 OpenGL 和 OpenGL ES 的新手) 在OpenGL上看起来很简单,但在ES上只能画三角形。
但我找不到任何关于此的好的教程:-( 是否存在任何包装器/库或其他任何可以帮助我的东西?
我不想使用 CoreGraphics,它对于我正在做的事情来说太慢了 ^^
如果可能的话,避免像 Cocos2D 这样太大的库。
编辑:解决问题,这里有一些有用的链接(将编辑)
链接
- 多边形三角测量
http://www.vterrain.org/Implementation/Libs/triangulate.html
http://en.wikipedia.org/wiki/Polygon_triangulation (WIKI) http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml(没有多边形孔) http://www.cs.unc.edu/~dm/ CODE/GEM/chapter.html(带孔的多边形,C 代码)
解决方案
我将尝试使用多边形镶嵌来获取三角形。首先我要尝试( http://www.flipcode.com/archives/Efficient_Polygon_Triangulation .shtml ),因为我需要带孔的多边形,所以第二个( http://www.cs.unc.edu/~dm/CODE/GEM/chapter.html )。 如果有人有更好的方法,请评论告诉我 ^^
谢谢:-)
I tried googling and searching on stack but I didn't find anything :-(
( Mapping irregular shapes or other polygons (cartoons, sprites) to triangles in OpenGL ES )
I want to draw a filled polygon in OpenGL ES on iPad (2D, don't need 3D)
(I'm new to OpenGL && OpenGL ES)
It seems simple on OpenGL but with ES with just can draw triangle.
But I can't find any good tutorial about this :-(
Does it exist any wrapper / library or anything else that could help me ?
I don't want to use CoreGraphics, it's too slow for what I'm doing ^^
And if possible, avoiding too (big) library like Cocos2D.
Edit : Working On the Problem, here are some useful links (will edit)
Links
- Polygon Triangulation
http://www.vterrain.org/Implementation/Libs/triangulate.html
http://en.wikipedia.org/wiki/Polygon_triangulation (WIKI)
http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml (polygon WITHOUT holes)
http://www.cs.unc.edu/~dm/CODE/GEM/chapter.html (polygon WITH holes, C code)
Solution
I will try using polygon tessellation to get triangles. At first I'm going to try ( http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml ) and as I need polygon with holes, the second one ( http://www.cs.unc.edu/~dm/CODE/GEM/chapter.html ). If anyone has a better way, PLEASE, tell me with a comment ^^
Thanks :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我还没有尝试过使用 OpenGL ES,但是从文档中的快速浏览来看,您应该能够使用例如“三角扇”来绘制凸多边形:
您可以认为是一个“三角扇” ”作为自行车车轮的辐条,将车轮区域划分为“三角形”(自行车车轮的外边缘当然是圆形的,但我希望您明白这一点)。
更新:我在网上找到了一个小图表:
I haven't tried using OpenGL ES, but judging from a quick look in the documentation you should be able to draw a convex polygon using e.g. a "triangle fan":
You can think of a "triangle fan" as the spokes of a bicycle-wheel dividing the area of the wheel into "triangles" (the outer edge of a bicycle wheel is of course round, but I hope you get the idea).
UPDATE: I found a small diagram on the web:
Cocos2D 是一个很酷的封装 OpenGL 的库,具有许多有用的功能(主要用于游戏但不限于)。
对于多边形镶嵌使用:
http://flipcode.net/archives/Efficient_Polygon_Triangulation.shtml
我以前用过它并且效果很好。
Cocos2D is cool library wrapping OpenGL and has many useful features ( mainly for games but not limited to ).
For polygon tessellation use :
http://flipcode.net/archives/Efficient_Polygon_Triangulation.shtml
I've used it before and it worked well.
在维基百科多边形三角测量讨论页面上,我认为更多的三角形实际上会更快。
我编写了一个三角剖分引擎,它支持孔并在O中运行(n log (n)) 时间。我在 Gdk 下测试了它,然后用它制作了一个 Android 应用程序。
On the Wikipedia Polygon Triangulation Talk page I argue that more triangles will in fact be faster.
I have written a triangulation engine that supports holes and runs in O(n log (n)) time. I tested it under Gdk and then made an Android app from it.
你的最终选择是什么?
我最近测试了下面链接中列出的 5 个库: http://vterrain.org/Implementation/Libs /triangulate.html
但没有一个令人满意...
iphone-glu: (http://code.google.com/p/iphone-glu/)
Triangulte:(http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml)
三角测量:(http://www.cs.unc.edu/~dm/代码/GEM/chapter.html)
poly2tri: (http://code.google.com/p/poly2tri/)
openglespolygon:(https://github.com/nroets/OpenGlEsPolygon)
What is your final choice?
I recently tested 5 of the libs listed in below link: http://vterrain.org/Implementation/Libs/triangulate.html
But NONE of them is satisfying...
iphone-glu: (http://code.google.com/p/iphone-glu/)
Triangulte: (http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml)
Triangulation: (http://www.cs.unc.edu/~dm/CODE/GEM/chapter.html)
poly2tri: (http://code.google.com/p/poly2tri/)
openglespolygon: (https://github.com/nroets/OpenGlEsPolygon)
在非 ES OpenGL 中,人们倾向于使用 GL Utility (glu) 库中的曲面细分器。我发现这个项目旨在让 glu 可用于 iPhone,并且声称支持多边形镶嵌 - 如果它有效,那么它将是一个不错的选择。
In non-ES OpenGL one would tend to use the tessellator from the GL Utility (glu) library. I found this project which aims to make glu available for the iPhone and it claims to support polygon tessellation - if it works, then it would be a good option.
当您需要对带孔的多边形进行三角测量时,可以尝试使用 GPC 。
有一个名为 gpc_polygon_to_tristrip 的三角函数。
对于渲染,请使用
GL_TRIANGLE_STRIP
。但请先阅读 gpc 许可证!
When you need do triangulation of polygons with holes, you can try use GPC.
There is function for tringulation called
gpc_polygon_to_tristrip
.For render use
GL_TRIANGLE_STRIP
.But read gpc license first!