View Full Version : Overlapped 2D Plane and Z buffer
02-27-2006, 12:50 PM
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!
02-28-2006, 02:00 AM
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.
02-28-2006, 03:31 AM
You could just turn off the depth test. Then the surface that is drawn last "wins".
02-28-2006, 05:46 AM
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?
02-28-2006, 10:32 PM
Use glVertex3... instead of glVertex2... when you render something.
03-01-2006, 01:03 AM
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 ;) ).
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.