GL_POLYGON trouble

Member
Posts: 148
Joined: 2003.03
Post: #1
I'm trying to remake SFCave (http://hp.vector.co.jp/authors/VA003665/...ave-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.
Quote this message in a reply
henryj
Unregistered
 
Post: #2
Got a screen shot?
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #3
Oh, you stepped into the dark corner of graphics. Smile 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. Smile
Quote this message in a reply
Member
Posts: 304
Joined: 2002.04
Post: #4
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.
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #5
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)

[Image: idevgames_post.jpg]

the red lines are drawn using GL_LINE_LOOP, whereas the dark gray is drawn with GL_POLYGON (obviously).
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
Well, the dark gray is not a convex polygon, so the results are undefined. I think you'll have to split it up.
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #7
Alright, i guess ill have to do it that way. Thanks.

*sigh* more work for me =P
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #8
Just wanted to let you know that i solved the problem using quad-strips. Everything looks beautiful now. Expect a release very soon. Grin

Thanks.
Quote this message in a reply
Post Reply