Sign in to follow this  
Desa

drawing lines over polygons

Recommended Posts

I have a surface and I want to draw the wireframe version over the filled version. If I simply draw the lines and quads together I get this. If I use a stencil buffer, I get the effect I want. I draw the lines into the stencil buffer and then draw the quads. But this approach doesn't take into account the depth buffer so my surface looks like this when viewed from the side. So, how do I draw lines and quads together while taking into account the depth buffer? Thanks.

Share this post


Link to post
Share on other sites
Two solutions in mind
One:
a. Render your terrain with ZWrite on but no color write
b. Render your lines to the stencil. Z has already been filled so only visible lines will be written.
c. Clear the zbuffer (not the stencil) and render your terrain.

Two:
a. Render your terrain.
b. Render your lines but using a sligthly higher ground (that is 0.001 higher). This is because it looks like your lines are fighting the zbuffer thats why you get that cut lines. If you render a little higher your lines will always be written.

Luck!
Guimo


Share this post


Link to post
Share on other sites
You can use something like glPolygonOffset (I forget the name) to add a small amount to the depth value of each fragment. This will give you the results you are after.


glPolygonMode(GL_FILL);
//render surface

glPolygonMode(GL_EDGE);
glPolygonOffset(epsilon);
//render surface



Can't recall the function names, and don't have my reference handy, sorry.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kuladus
You can use something like glPolygonOffset (I forget the name) to add a small amount to the depth value of each fragment. This will give you the results you are after.


glPolygonMode(GL_FILL);
//render surface

glPolygonMode(GL_EDGE);
glPolygonOffset(epsilon);
//render surface



Can't recall the function names, and don't have my reference handy, sorry.


How exactly does polygon offset work... would you be able to see the lines from either side of the polygons? I noticed that it takes a single float parameter, so how does it use the parameter?

I want to use this method for decaling, but I'd like to understand how it works.

Edit: also, do you have to undo the polygonoffset? or does switching the fill mode change it back to 0?

[Edited by - LEET_developer on July 21, 2005 6:03:10 PM]

Share this post


Link to post
Share on other sites
I am using it like this. I'm not sure how it works, but I can see the lines from both sides of the surface.

// draw lines
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

// enable polygon offset
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);

// draw quads
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this