OpenGL ES - How to Draw a filled Polygon?

前端 未结 6 1462
小蘑菇
小蘑菇 2020-12-28 22:22

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 )

相关标签:
6条回答
  • 2020-12-28 22:50

    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.

    0 讨论(0)
  • 2020-12-28 22:52

    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.

    0 讨论(0)
  • 2020-12-28 23:00

    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

    0 讨论(0)
  • 2020-12-28 23:04

    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!

    0 讨论(0)
  • 2020-12-28 23:09

    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.

    0 讨论(0)
  • 2020-12-28 23:12

    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
    0 讨论(0)
提交回复
热议问题