Hidden line

hi anyone knows a fast routines to hide lines in a wireframe model in opengl?

Maybe this could work, if you’re willing to do two passes.

-glPolygonMode(…,GL_FILL);
-enable depth,clear depth
-disable color buffer writes
-Draw every polygon
-glDepthFunc(GL_EQUAL);
-glPolgonMode(…,GL_LINE);
-enable color buffer writes
-Draw every polygon

glPolygonMode(…,GL_LINE) is fairly slow though. Maybe drawing GL_LINES and implementing a hidden-line algo is faster(there are a few out there).

Just a thought.

[This message has been edited by roffe (edited 02-27-2003).]

That doesn’t quite work as you would like. Lines and polygons aren’t depth-invariant so you will fight like mad. You generally need to use polygon offset to push the first pass back a little.

-Evan

This guy has a demo with source about Hidden line removal.
http://www.xmission.com/~pdalton/opengl.html

Originally posted by ehart:

Lines and polygons aren’t depth-invariant so you will fight like mad.

Ok thanks. Just out of curiosity, how does these three types of rasterizations “differ”:

  • rendering polygons with glPolygonMode(…,GL_FILL)
  • rendering polygons with glPolygonMode(…,GL_LINES);
  • rendering GL_LINES

Is “polys-with-GL_LINE” renderings more like “polys-with-GL_FILL” or “GL_LINES” when it comes to rasterization? Maybe completely different?

Originally posted by roffe:
- rendering polygons with glPolygonMode(…,GL_FILL)

This will render you polygons (triangles) filled in (ie. Solid)

[b]

  • rendering polygons with glPolygonMode(…,GL_LINES);
    [/b]

This will render the outlines of your polygons only (wire frame).

[b]

  • rendering GL_LINES
    [/b]

This will render a bunch of lines.

Method 3 can be more efficient in terms of rendering. If you render a triangle using GL_LINES it will render 3 edges - so there will be double the rendering, more or less, where triangles meet. If you just render GL_LINES then you can cut down the rendering by only rendering each edge once.

However, if you render triangles and have PolygonMode(GL_LINES) you can use cullface to remove the rearward facing polygons.

If you are trying to only render the forward facing parts of the mesh then you can use roffe’s technique with Evan’s correction or you can render triangles using PolygonMode(GL_LINE) with glCullFace(GL_BACK) and glEnable(GL_CULL_FACE).

Ok, thanks, I know how these functions work. That wasn’t my question. Read my first post.

My question was regarding Evan’s comment. Usually lines and polygons rasterize differently. I wanted to know if there was a major difference in the rasterization of GL_LINES and GL_ANYPOLY with PolygonMode(…,GL_LINE).

I tried this technique by editing one of nate robbins turorials, and it seems to work just fine on the models he uses. See for yourself: http://www.efd.lth.se/~e98mp/lightmaterial.exe

If you dont have his models you can only use the torus.

If you toggle ‘t’ you can switch between hidden lines and not. Code uses a depthfunc of GL_LEQUAL instead of just GL_EQUAL, which I should have thought of. If you just respect z-buffer limitations I cant see why this technique shouldn’t work.

Originally posted by rgpc:

However, if you render triangles and have PolygonMode(GL_LINES) you can use cullface to remove the rearward facing polygons.

This wont work if your ENTIRE object is concave, not saying that the individual polys that make up the object is. It will give you a speed up though.