As the subject suggest, I am quite new to OpenGL. I've read the 'Super
Bible', and can get some stuff working, like drawing shaded or texture
mapped polygons in space. However, I am quite at loss with how I can draw
multiple solid objects, that removes 'eachothers' hidden surfaces, without
using textures or shading
The 'effect' I would like to achive is similar to drawing all polygons
using PolygonMode(GL_FRONT, GL_FILL) in the background color, (and
depthtest+backface culling) then drawing the same polygons, using
PolygonMode(GL_FRONT, GL_LINE) in the foreground color. But this
(obviously) introduces visual artifacts, which I guess is because different
points/z values are beeing used/interpolated in each mode?
I think I understand what backface culling does. I also think I understand
the depth buffer - at least to some extent. I can't see how I can achive
the effect I want using these only. I've tried using the operation that
offsets the depth buffer (forgot its name right now, sorry. DepthOffset?),
but I haven't had any succes.
If this was something I was to implement in software myself, I would
probably draw my polygons to a separate color and Z buffer, saving the span
lists. Then I would draw the borders, ignoring, but keeping the Z values,
and then finally merge the picture into the main framebuffer using my saved
spanlists. But I hardly think this is the way to go in OpenGL? (And I am
not even sure it would work...).
Can anybody give me a hint to what I should do? I've seen very nice
implementations in OpenGL of this (not the source, obviously ;-) - and it
must be possible.
Thanks in advance.
Mads
P.S. I tried looking for a FAQ on this - honestly, I did. If it is a FAQ,
then I would appriciate someone hitting me in the head with a URL or other
reference. Thanks.
--
Mads Bondo Dydensborg mad...@diku.dk
Quake/Delphi/Windsurfing info: http://www.diku.dk/students/madsdyd/
---------------------------------------------------------------------
"I've been told, that to look cool on the internet, it is required to
spread enourmous ascii chunks around in your signature. To save my
phone bill, I've included the following 'virtual-very-large-sig' : *
Am I cOoL nOw? Or do I need to make huge quotes as well? " - Mads
Different Z values, correct. Lines (edges, borders, whatever) do not
have the plane equation information found in filled primitives. So
when OpenGL renders a line, it must simply interpolate Z from one
endpoint to the other, whereas for filled primitives, the Z values are
interpolated across the filled primitive plane.
: I've tried using the operation that
: offsets the depth buffer (forgot its name right now, sorry. DepthOffset?),
: but I haven't had any succes.
"glPolygonOffset" I think you mean. You supply two parameters, one
multiplies the max Z slope, the other multiplies the minimum
resolvable Z value. I've found "glPolygonOffset (1, 1)" produces
acceptable results most of the time, and introduces a minimum of
artifacts resulting from the offset itself.
You'll also want to be sure you enable polygon offset correctly. A
typical usage for your case might be:
glPolygonMode (GL_FRONT, GL_FILL);
.../* render model, fill pass */...
glPolygonMode (GL_FRONT, GL_LINE);
glPolygonOffset (1, 1);
glEnable (GL_POLYGON_OFFSET_LINE);
.../* render model again, line pass */...
Of course this assumes you are using OpenGL 1.1. If you have OpenGL
1.0, polygon offset may be available as an extension. The parameters
and calls and constants are all different though.
Another trick is to change the range of the depth buffer you're
writing into using glDepthRange. However, glPolygonOffset is really
the preferable method and results in a better image.
: If this was something I was to implement in software myself, I would
: probably draw my polygons to a separate color and Z buffer, saving the span
: lists. Then I would draw the borders, ignoring, but keeping the Z values,
: and then finally merge the picture into the main framebuffer using my saved
: spanlists.
This would work great as long as you cull backfaces and only have
convex solids. And you can implement this algorithm in OpenGL without
a seperate color and Z buffer:
.../* render model, fill pass */...
glDepthMask (GL_FALSE);
glDepthFunc (GL_ALWAYS);
.../* render model, line pass */...
Good luck with your work...
--
-paul ma...@shaft.fc.hp.com
Hewlett-Packard Company
"Technology can be used for good or evil.
Please use only for good."