View Full Version : Draw objects at the same position

05-01-2008, 07:27 PM
I am writing a small application that used opengl library and I met a problem as follow. When I draw some objects at the same position they blend together. for example some lines in this image become dot.

http://img241.imageshack.us/img241/9347/bugxo6.png (http://imageshack.us)
Could you please tell me how to fix this problem. I would like to appreciate your help on this


05-02-2008, 02:38 AM
I suppose it's a z-fighting problem.

This webpage (http://www.opengl.org/resources/faq/technical/polygonoffset.htm) and a google search (http://www.google.com/search?q=z-fighting) should help you.

05-04-2008, 07:49 PM
Could you please tell me the best solution to fix this problem

05-05-2008, 01:34 AM
You can try this (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=237040#Post237040).

05-07-2008, 09:52 PM
Thanks, I tried this and it seems that it works well, but I meet another problem when I fill on a face of a wall some time they blend together as the image bellow. could you please tell me how to fix it? thank you very much

http://img170.imageshack.us/img170/4071/blendts4.png (http://imageshack.us)

05-08-2008, 03:25 AM
Can you post your rendering call where you setup the projection matrices and render the quads/lines? The gray lines seem to render above the blue surface just fine. Maybe the offset for the white lines just isn't large enough.

05-08-2008, 06:46 AM
Looks like he means the blue face is rendered on a white face and the white lines is bleed-through corruption from the white block underneath.
In that case you need to (polygon-)offset the two faces from another as well. That is, shift the blue faces nearer to the viewer and the grey lines on top of the blue with it as you did before.

05-11-2008, 07:29 PM
Yes, the white lines appear when I fill a blue face on a white face as the image bellow

http://img525.imageshack.us/img525/1355/stripebuggb1.png (http://imageshack.us)

I used this function to shift the line nearer the viewer and the line problem is fixed

GL.PolygonOffset(1, 0.0001f);

Could you please tell me which function should I used to fix this bug

05-12-2008, 12:20 PM
That was for the blue face only? Which would push the blue face about a depth unit back.

Now you need to render the whole white block with an even bigger offset and that should separate the white from the blue face.

The order in which you render the things doesn't matter with depth test enabled, just make sure they are separated from each other enough with polygon offset to prohibit depth bleeding.

// depth test is enabled
DrawTheGreyLines(); // These are rendered at their original depth and should come out in front.
GL.PolygonOffset(1.0f, 1.0f);
DrawTheBlueFace(); // This goes behind the grey lines.
GL.PolygonOffset(2.0f, 2.0f);
DrawTheWhiteBox(); // This goes behind the blue face.

05-14-2008, 01:33 AM
Thank you for your help, it works well