View Full Version : Drawing a full line over a stippled line

11-02-2010, 04:11 AM

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 (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Main=54551&Number=2824 61#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?



11-02-2010, 06:20 AM
Well drawing the lines over stippled lines should indeed cover them.
Can you post a screenshot ?

11-02-2010, 06:35 AM
Good suggestion. Here's one. You can best see the problem on the bottom right model.

11-02-2010, 07:49 AM
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.

11-03-2010, 12:47 AM
Thanks for the tip, it worked perfectly!

11-03-2010, 09:26 AM
You could also set the dotted lines to only draw when they have a depth greater than the value in the depth buffer;)

11-03-2010, 12:00 PM
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.

11-03-2010, 12:03 PM
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.

11-03-2010, 12:18 PM
Good points. Yes, you're right. Thanks for the tip!

11-04-2010, 01:34 AM
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?

11-04-2010, 06:32 AM
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.

11-04-2010, 01:13 PM
when using glDepthFunc(GL_GREATER), be sure to call glDepthMask(GL_FALSE)