PDA

View Full Version : GL_POLYGON trouble


MacFiend
2003.05.04, 07:12 PM
I'm trying to remake SFCave (http://hp.vector.co.jp/authors/VA003665/others/javacave-e.html ) in OpenGL.

I've got everything down pretty good. When I draw the cave using GL_LINE_LOOP, everything is fine. However, when I draw the cave using GL_POLYGON, there are minor discrepancies in the outcome. Some parts of the cave seem to be left out when drawn, resulting in an ugly look. The top of the cave is supposed to look like it fits perfectly into the bottom of the cave. When I draw using GL_LINE_LOOP, that is the case, everything is perfect. But when I draw using GL_POLYGON (this is what I want to do for the final product), the top of the cave does not "match" (lock and key type of thing) the bottom. Any ideas why? Thanks.

henryj
2003.05.04, 07:57 PM
Got a screen shot?

Fenris
2003.05.04, 08:55 PM
Oh, you stepped into the dark corner of graphics. :) In short, anything you draw with GL_POLYGON must be convex. So, if your polygon is concave, then you have to break it up into smaller convex sections. (Which means that you're going to break it into triangles at some point.) Google for tesselation, or get in the ring with gluTesselator. (Chapter 11 in the Red Book.)

Good luck, I tell you. :)

codemattic
2003.05.04, 11:02 PM
Fenris is right. But if you are creating the tunnel from that java game (fun!) it should be pretty obvious where to break it up into triangles - or into a triangle strip.

And maybe check out the post "Collision Detection (Point-Polygon)" for algorithms to collide a point with a triangle to handle your collisions.

good luck.

MacFiend
2003.05.04, 11:24 PM
im not quite sure its a problem with concave/convex polygons. it appears to happen randomly, although i may be mistaken.

here is a screenshot (note: this image will only be up for a short amount of time)

http://129.44.120.175:81/idevgames_post.jpg

the red lines are drawn using GL_LINE_LOOP, whereas the dark gray is drawn with GL_POLYGON (obviously).

OneSadCookie
2003.05.04, 11:38 PM
Well, the dark gray is not a convex polygon, so the results are undefined. I think you'll have to split it up.

MacFiend
2003.05.04, 11:45 PM
Alright, i guess ill have to do it that way. Thanks.

*sigh* more work for me =P

MacFiend
2003.05.06, 06:39 AM
Just wanted to let you know that i solved the problem using quad-strips. Everything looks beautiful now. Expect a release very soon. :D

Thanks.