Intersecting polygons and clipping

Hi, I’m having a problem with intersecting polygons. The green and red triangles below represent a solid plane. What I would like to do is have the blue triangles stop rendering where they meet the red and green triangles so you can’t see them below the red/green plane. The blue triangles are perpendicular to the red/green plane. I’ve tried every trick I could think of for the z-buffer but nothing I am doing is working. Can someone please point me in the right direction? Below is attached an image of the problem. Thanks!

did you do all of the following:

  • choose a pixelformat with depth buffer
  • glEnable(GL_DEPTH_TEST)
  • glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

?

I did #2 and #3. How would I go about choosing the pixel format for the depth buffer?

Did you create a rendering context?

Yes I did. I also checked into things like PolygonOffset, Depth fuctions, alpha blending, etc. but to no avail. I’m guessing that the problem has something to do with the z-buffer but I feel I’ve exhausted all of my options. So I’m appealing to you guys.

What

GLint dbb;
glGetIntegerv (GL_DEPTH_BITS, &dbb);

returns in dbb ?

From your image it look like the blue triangles don’t intersect the red-green at all, but are just in from of them. Am I missing something? Maybe you got wrong coordinates? What happen when you render the blue triangles first and the red-green last?

If in your gluPerspective call you have the depth buffer range set unusually large (the last two arguments), that could happen due to unlucky rounding, I think.

Originally posted by Zengar:
From your image it look like the blue triangles don’t intersect the red-green at all, but are just in from of them. Am I missing something? Maybe you got wrong coordinates? What happen when you render the blue triangles first and the red-green last?
Yes, I realize this. I’m able to mouse around and rotate things, so I am completely sure the blue triangles intersect exactly in the middle of the red and green triangles.

As for the gluPerspective, I have the numbers 1.0 and 1000.0 for the last two parameters.