Draw a triangle and his borders too??

http://www.opengl.org/wiki/index.php/General_OpenGL:_The_Depth_Buffer

I was able to set the Depth buffer size to 24 bits but it didn’t do it, I guess the problem is with the depth range.

I’ll read more on the depth buffer and get back to you guys.

that’s great, vincent. let us know how it works out.

When you modify the depth range, first put out the near plane as far as possible. For your values, changing the near plane to 0.2 would have the same effect as changing the far plane to 100 :wink: .

Just try some other near values, like 0.5 or even 1.0, this should dramatically increase depth precision.

I tried playing with the near/far values but id didn’t change except sometimes it would clip parts of the drawing…

I’ll upload a video sample soon :wink:

Here it is!! Video sample Video sample 2

If I understand correctly, the depth buffer precision is affected by zNear and zFar, which are in the line

gluPerspective(45, aspectRatio, 1.0, 200); 

1.0 being the “Near” value, 200 being the “far” one.

(I actually thought this was used for clipping purposes only)

To get a better buffer precision I have to push the NEAR to the biggest number possible and lower the FAR to the lowest number possible?

I tried setting it to 3.0 and 150 and it didn’t change much, in fact I think it made it worse.

yep. Looks like you’ve got a handle on it.

I see you’ve still got some glitches. Looks like maybe your polygonoffset and/or near/far values need some more tweaking. Like I said, this isn’t perfect, but it shouldn’t be nearly that bad, not in such a small range.

You should really get rid of that polygon offset. It’s unreliable and scene-setup specific.

Have you tried a simple two pass approach:

  • enable depth buffer

  • setup depth function to less than or equal to

  • enable depth write

  • draw solid mesh

  • disable depth write but keep the depth testing enabled (this might even be optional)

  • draw wireframe mesh

< edit: terminology changed >