简体   繁体   中英

GL_TRIANGLES filling makes curve straight

EDIT: I had written GL_POLYGONS instead of GL_TRIANGLES, sorry

I have a shape which comprises of a 2 joined bezier curves. I'm trying to fill it using GL_TRIANGLES about an internal point. Here are the results:

在此处输入图片说明

On the right is the actual shape displayed via GL_LINE_STRIP.
On the left is the result after GL_TRIANGLES after giving the points in a triangular way.

As you can see, the curvy shape has disappeared and instead it's (almost) a straight edge.

Any idea how can I fix this? Or maybe a better way to fill such shapes?

Things supplied to GL_POLYGON must be convex. Your object is concave.

If you know that your shape is always going to appear convex if approached from one direction — eg with your shape I can definitely say that any horizontal line is going to hit exactly two boundaries — then you can approach it as a triangle strip.

If you don't know anything at all about your polygon in advance, you need to look into tesselation, which is any number of algorithms for reducing an arbitrary polygon to a list of convex polygons that cover the same area. GLU contains a tesselator for which simple use is described here . The Wikipedia article on triangulation neatly summarises the most popular algorithms if you want to implement your own, and Mesa provides an open source implementation of GLU if your platform doesn't already have it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM