Jump to content
  • Advertisement
Sign in to follow this  
AEtheReal

OpenGL Drawing polygons using triangles

This topic is 3065 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have written a program for simple drawing which uses GDI+. I heard that using graphics library like OpenGL can speed up the drawing process, so now I am converting the code to use OpenGL instead of GDI+. For each function (e.g. FillEllipse, DrawImage, FillPolygon) I used in GDI+, I try to implement it using OpenGL. When I am trying to code FillPolygon, I encounter a big problem, which is completely out of my expectation. OpenGL can draw triangle strip and fan, which does not work when the polygon is convex. To make things even worse, the polygon may not be simple. There may be self-overlapping. In the FillPolygon call in GDI+, the area that is include an odd number of times is filled. For example, when the shape "8" is passed to the procedure, it fills the two loops. It is extremely important to cope with non-simple polygon in my program, since the polygon may undergo conplex transformations that cannot guarantee that the resultant polygon is simple. If the polygon is drawn incorrectly, the output may become flickery. However it seems very difficult to replicate this using OpenGL. I guess the only way to do this is to divide the polygon into triangles. I cannot think of any algorithm that can run in reasonable time. GDI+ can draw polygons with hundreds of vertices in 30fps. I hope to attain at least comparable result. I would like to ask if there is any fast algorithms to break an arbitrary polygon into triangles? Or are there any tricks to get around it?

Share this post


Link to post
Share on other sites
Advertisement
Look at using the stencil buffer to implement your fill rules, you can simply submit your vertices as a triangle fan and the stencil will do the rest, cutting out the areas that should be convave/holes etc. Depending on the stencil rules used you can quite easily emulate a number of fill rules inclusing even-odd and non-zero.

General triangulation (with concavity, self intersection, and holes) is a much harder solution, and unless you have the opportunity to generate the triangulated data off-line it is very difficult to make fast enough for real time applications. If you are interested take a look at ear clipping or Seidel's algorithms.

It should be pretty easy to find information on both of the above.

Best of luck,

Alex

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!