Soundbomber's picture

Depth testing

I am drawing a series of connected lines that make up the outline of a shape.
When I render the shape with depth testing on, I get undesirable results (see attached file 1).
I have used very thick lines to illustrate this better, but each line segment of the curve when layed out in order seems to have a border that 'masks' the preceding line segment.
With depth testing off this doesn't happen (see attached file 2).
Anyone any ideas how to overcome this?

Inline Images


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

This looks similar to z-fighting, which occurs when the z-buffer does not have enough precision to resolve close objects.

Are you drawing each line segment separately? If so, try drawing them in one go (BeginMode.LineStrip).

You can also request a GraphicsMode with a 24/32-bit zbuffer for better precision. GameWindow and GLControl have constructors that allow you to do this (note that you'll have to inherit from GLControl to access its constructor). If 24bits are not enough, you can add a very small offset to adjustent segments.

Soundbomber's picture

Thanks Fiddler, think it is z-fighting. Resolved it by using GL.DepthFunc(DepthFunction.Lequal).

Kamujin's picture

I had this same problem for my GUI framework and was surprised to learn that DepthFunction.Lequal was not the default. I guess my prior experience with DirectX had skewed my perception of "normal".