Draw objects at the same position

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.


Could you please tell me how to fix this problem. I would like to appreciate your help on this

Thanks,

I suppose it’s a z-fighting problem.

This webpage and a google search should help you.

Could you please tell me the best solution to fix this problem

You can try this.

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

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.

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.

Yes, the white lines appear when I fill a blue face on a white face as the image bellow

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

GL.Enable(GL.POLYGON_OFFSET_FILL);
GL.PolygonOffset(1, 0.0001f);

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

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.Enable(GL.POLYGON_OFFSET_FILL);
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.
GL.Disable(GL.POLYGON_OFFSET_FILL);

Thank you for your help, it works well