Drawing a full line over a stippled line


I’m drawing 3D shapes using a technique pointed out by another user of this forum some times ago. The idea is to draw the shape in 3 passes, so that edges that should be hidden will be drawn with stipple lines, and other edges will be draw fully. For more details: http://www.opengl.org/discussion_boards/…2461#Post282461

Now this works great, but the problem is that you can still see the stippled lines even when another line is drawn on top of it. Ideally, you should not be able to see it, though. I’ve tried playing with the transparency, and also simply drawing full lines bigger than stippled lines, but you can still see the stippled lines.

This is probably a simple problem, but the first time that I encounter it. Any hints on how to solve it?



Well drawing the lines over stippled lines should indeed cover them.
Can you post a screenshot ?

Good suggestion. Here’s one. You can best see the problem on the bottom right model.

Ah ok, the problem is not dotted lines, but depth test.
Use polygon offset to shift away the filled faces depth a bit, so the full lines will pass the depth test completely instead of half of it.

Thanks for the tip, it worked perfectly!

You could also set the dotted lines to only draw when they have a depth greater than the value in the depth buffer;)

No, that won’t work reliably. That would only render lines that are behind the furthest geometry at each pixel fragment. But if you have concave geometry (for example, imagine a V shape, viewed from the edge), there may be hidden lines that are NOT at the back of the model.

Surely it would render lines whenever they are further away than the closest geometry, since the depth buffer only stores the closest depth.

As far as I can tell, you want every part of every line to be either dotted or solid. Since the solid only ever draws when it is closer or equal to the depth in the depth buffer, it makes sense that the dotted should draw when it is further away than the depth in the depth buffer.

Good points. Yes, you’re right. Thanks for the tip!

Interesting idea, but how would you do it? I mean, for now I draw the dotted lines before the plain lines. But there are some edges where only dotted lines should be drawn, and in this case they are “behind” the plain lines. So I don’t really get how your solution would work, could you explain more?

Sorry hadn’t refreshed the page and did not see the discussion. I see the idea now, but the implementation is not quite clear to me.

First, I read somewhere that accessing the z-buffer could be very slow. Is that true? And second, is there a way to determine the “would be depth” of a point without drawing it?

Normally, pixels are only drawn when the depth of that pixel is closer than the depth stored in the depth buffer. All I’m suggesting is changing the comparison mode to only draw if it’s further away.

You can do this using ‘glDepthFunc’. This method should have a small performance increase over the other method since each pixel is only drawn once.

When drawing the dotted lines, use ‘glDepthFunc(GL_GREATER)’ and when drawing the solid lines, use ‘glDepthFunc(GL_LEQUAL)’.

Remember to set it back to ‘glDepthFunc(GL_LESS)’ when you’ve finished drawing, in-case other code depends on it.

You should’t need to use the polygon offset command which ZbuffeR suggested with this method either.

when using glDepthFunc(GL_GREATER), be sure to call glDepthMask(GL_FALSE)