
I'm reading the red book and it says opengl cannot render convex polygons. Yet, when I compile this code: renderPrimitive Polygon $ do vertex $ Vertex2 0 (0::GLfloat) vertex $ Vertex2 0 (3::GLfloat) vertex $ Vertex2 4 (3::GLfloat) vertex $ Vertex2 3 (1.5::GLfloat) vertex $ Vertex2 4 (0::GLfloat) The convex polygon is displayed correctly. Does hopengl do something behind the scenes or I just "lucked" out that my opengl/hardware can handle this particular convex polygon case?

No, HOpenGL doesn't do anything behind the scenes; it's not that
OpenGL can't render convex polygons so much as it's a bad idea to
count on it rendering them. It's entirely implementation (read video
card) dependent as to whether it can render them and if it can how
complicated they can be before the implementation breaks. It's sort
of like how IE and Firefox will render HTML that isn't XHTML compliant
or even truly really HTML. It's much better practice to tesselate
using the GLU functions or your own tesselator than it is to count on
features that are only there to correct the occasional programmer
mistake.
On Sun, Mar 22, 2009 at 5:27 PM, Rafael Cunha de Almeida
I'm reading the red book and it says opengl cannot render convex polygons. Yet, when I compile this code: renderPrimitive Polygon $ do vertex $ Vertex2 0 (0::GLfloat) vertex $ Vertex2 0 (3::GLfloat) vertex $ Vertex2 4 (3::GLfloat) vertex $ Vertex2 3 (1.5::GLfloat) vertex $ Vertex2 4 (0::GLfloat) The convex polygon is displayed correctly. Does hopengl do something behind the scenes or I just "lucked" out that my opengl/hardware can handle this particular convex polygon case? _______________________________________________ HOpenGL mailing list HOpenGL@haskell.org http://www.haskell.org/mailman/listinfo/hopengl

Your result is typical. OpenGL has to tesselate the polygon into triangles. In some cases it will tesselate a concave polygon correctly. For example, if you plot that using TriangleFan, I'm doing this mentally, but I think it comes out correctly. Also, convex is the kind of polygon that opengl *can* render. The polygon you described is concave. If you were hoping to render the convex hull of the polygon, you'll have calculate that yourself. --Lane On Sun, 22 Mar 2009, Rafael Cunha de Almeida wrote:
I'm reading the red book and it says opengl cannot render convex polygons. Yet, when I compile this code: renderPrimitive Polygon $ do vertex $ Vertex2 0 (0::GLfloat) vertex $ Vertex2 0 (3::GLfloat) vertex $ Vertex2 4 (3::GLfloat) vertex $ Vertex2 3 (1.5::GLfloat) vertex $ Vertex2 4 (0::GLfloat) The convex polygon is displayed correctly. Does hopengl do something behind the scenes or I just "lucked" out that my opengl/hardware can handle this particular convex polygon case? _______________________________________________ HOpenGL mailing list HOpenGL@haskell.org http://www.haskell.org/mailman/listinfo/hopengl
participants (3)
-
Christopher Lane Hinson
-
Jeff Heard
-
Rafael Cunha de Almeida