OpenGL ES - 如何绘制填充多边形?

发布于 2024-09-26 11:44:43 字数 1693 浏览 11 评论 0原文

我尝试在堆栈上进行谷歌搜索和搜索,但没有找到任何东西:-(
( 映射不规则形状或其他多边形(卡通、精灵)到 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 技术交流群。

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

发布评论

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

评论(6

讽刺将军 2024-10-03 11:44:43

我还没有尝试过使用 OpenGL ES,但是从文档中的快速浏览来看,您应该能够使用例如“三角扇”来绘制多边形:

glVertexPointer(2, ..., arrayOfCoordinates)
...
glDrawElements(GL_TRIANGLE_FAN, ... , arrayOfIndices);

您可以认为是一个“三角扇” ”作为自行车车轮的辐条,将车轮区域划分为“三角形”(自行车车轮的外边缘当然是圆形的,但我希望您明白这一点)。

更新:我在网上找到了一个小图表:http://www.cse.msu。 edu/~cse472/step6_stuff/step6.1.gif

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":

glVertexPointer(2, ..., arrayOfCoordinates)
...
glDrawElements(GL_TRIANGLE_FAN, ... , arrayOfIndices);

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:http://www.cse.msu.edu/~cse472/step6_stuff/step6.1.gif

じее 2024-10-03 11:44:43

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.

神魇的王 2024-10-03 11:44:43

在维基百科多边形三角测量讨论页面上,我认为更多的三角形实际上会更快。

我编写了一个三角剖分引擎,它支持孔并在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.

抚笙 2024-10-03 11:44:43

你的最终选择是什么?
我最近测试了下面链接中列出的 5 个库: http://vterrain.org/Implementation/Libs /triangulate.html

但没有一个令人满意...

  1. iphone-glu: (http://code.google.com/p/iphone-glu/)

    • 算法中存在错误?有一些小孔未填充,或者有时绘制在多边形之外
  2. Triangulte:(http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml)

    • 不支持漏洞...
  3. 三角测量:(http://www.cs.unc.edu/~dm/代码/GEM/chapter.html)

    • 有问题,有时会超出范围,或负索引等...
  4. poly2tri: (http://code.google.com/p/poly2tri/)

    • 有问题,在某些情况下会崩溃
  5. 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...

  1. iphone-glu: (http://code.google.com/p/iphone-glu/)

    • Bugs in the algorithm? there are tiny holes not filled, or sometimes draw outside of the polygon
  2. Triangulte: (http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml)

    • doesn't support holes…
  3. Triangulation: (http://www.cs.unc.edu/~dm/CODE/GEM/chapter.html)

    • Buggy, sometimes runs out of bounds, or negative index etc...
  4. poly2tri: (http://code.google.com/p/poly2tri/)

    • Buggy, crash in certain cases
  5. openglespolygon: (https://github.com/nroets/OpenGlEsPolygon)

    • imperfect algorithm? there are tiny holes (not filled) along the edges of the polygon
深海少女心 2024-10-03 11:44:43

在非 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.

不再见 2024-10-03 11:44:43

当您需要对带孔的多边形进行三角测量时,可以尝试使用 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!

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