View Full Version : Hidden lines
I'd like to display hidden lines (lines behind an object)as dashed, like in a cad app, when in wire frame (line) mode. Do i use hidden surface removal with something else.
Any body have something similar or tuts to do this?
Thanks in advance, MickD
08-10-2003, 03:06 PM
Use a texture. Render with a dashed texture. If you don't want the dash to shrink or expand due to perspective, then look into using the stencil buffer.
You may have to render triangles so you can determine which lines are back facing, as well as using another tecqnique to determine if lines are occluded. Either way, I am sure the stencil buffer would be really helpful.
There are many other ways to do it, I am just giving you one idea, good luck.
08-10-2003, 03:13 PM
Oh, one more thing, take a look at glLineStipple().
Thanks for your reply.
The real problem i will encounter is when a line segment that is not 'behind' anthing for part of the line, then goes behind something.This is where i need the line to stipple. I'll do some more study on stencil etc.
08-10-2003, 09:49 PM
Actualy, it is very easy to solve that problem with the stencil buffer. One solution off the top of my head is to set the screen to some stencil value (say 1). Then when you render anything, it must only render to pixels with the value 1, once the fragment is rendered, then it should set the value to 0. This way, front facing polygons will not obscure dashed back facing ones.
Also, back facing polygons should always pass the stencil test since they are the ones that must produce dashed lines which show through. However, back facing polygons should still update the stencil value to prevent future overwrite by front facing polygons.
It may not work exactly like this since you will need to consider your depth buffer and transparent/translucent fragments, but I hope you get the idea.
The stencil buffer is a powerfull tool once you get the hang of it (although overdraw/fill rate may become a problem).
I saw a thread which suggested drawing the front facing polygons first, then the back facing polygons with stipple using front/back culling, is this a good approach or would it produce more overhead than using the stencil?
08-11-2003, 04:38 PM
Yes that would work, but I thought your real problem was for lines that are both in front and behind (partly occluded). The problem is the front facing lines which are partly occluded. You could use a bsp tree or something like it to make sure no lines are partly occluded. However this would require static geometry.
If you want to render complex dynamic geometry with back facing and occluded lines being dashed/dotted, then I recommend using the stencil buffer. The stencil buffer is not neccasary if you will have only convex geometry.
08-11-2003, 04:46 PM
If I have time I will post up a small solution function. You will find that it is rather straight forward. Although my solution would require one pass to render the geometry, and a final pass to dash/dot occluded lines.
Open up a paint program and experiment to see how you could use the stencil buffer to solve your problem. Good luck.
Thanks again hky, point taken.Looks like its back to the books!
Look forward to your solution (if you have time of course).
08-11-2003, 09:36 PM
Hey guess what, you don't need the stencil buffer at all. Although the solution is still a double pass.
Here is the pseudocode:
// Constant states are set here
glPolygonMode( GL_BACK, GL_LINE);
glLineStipple( 3, 0xAA);
// Main rendering loop
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
cam.process(); // Some viewing transformations
// First pass states
glPolygonMode( GL_FRONT, GL_FILL);
mdl.render(); // 1st pass to draw front facing filled polygons
// Second pass states
glPolygonMode( GL_FRONT, GL_LINE);
mdl.render(); // 2nd pass to draw dashed occluded/back facing polygons
As you can see, all you need is the depth buffer and speed (to render two passes).
Thanks again, will give it a go and let you know (could be a while, newbie status http://www.opengl.org/discussion_boards/ubb/smile.gif).
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.