Overlapped 2D Plane and Z buffer

Our application needs to draw a couple of 2D planes in a box frame. These planes are at the same height level, therefore they could overlap with each other. What I see on the screen looks like a mixture of the colors of these planes(correct me if I am wrong). Some part shows the color of plane 1 while another part could shows the color of plane 2. Is there any easy way to control which color wins in this case? Thanks a lot!

Not if they are all at the same distance from the viewer, if you overlap polygons at the exact same distance from the viewer you would get artifacts so you would need to ajust the distance to make sure the poygons don’t get artifacts.

If you are using orthographic projection you can change the Z value without having any impact on what you see so that should be easy to implement in that case.

You could just turn off the depth test. Then the surface that is drawn last “wins”.

Thanks. I did use orthographic projection. I specified the position of the planes by 3D coordinate, how can I change the Z value? We do need depth test to distinguish 2D planes and other drawing objects. Is there any way to solve my problem?

Use glVertex3… instead of glVertex2… when you render something.

There is also glPolygonOffset. It modifies the z value of the polygon without actually changing the position of the vertices.

When the plane is (nearly) parallel to the projection plane, you can just set the first parameter to zero, otherwise try experimenting with small values like 0.5 or 0.75…

The second parameter is what you want. Positive means farther away, negative means nearer. For example, -1.0 means “draw this one depth unit nearer to the camera”.

You can find a more complete description of the function and some example code in the redbook, chapter 6. For some reason it’s only in the pdf version, not in the html version (never realized until now that there is a difference between html and pdf/hardcopy :wink: ).