Capping Solid-Stencil Buffer-coplanar faces+artifa

Hello,

I am trying to use the stencil buffer to cap a clipped solid.

1- But the geometry contains coplanar faces and this creates artifacts : I guess it is the classical z-fighting.
It is too difficult to change the geometry ; Is there a way with opengl to manage the z-fighting problem ?

2- There is anoter artifact : a lot of edges of the non-clipped solids have the color of the capping plane. I guess that it is the same z-fighting problem on the intersection of 2 faces. How do you solve this problem ?

Thanks for your help

Z-Fighting can be avioded by small increments/decrements to the final z-values. OpenGL provides

glPolygonOffset(...)

and the state

GL_POLYGON_OFFSET_FILL

to account for situations like the one you mentioned.

Hello,

I did a quick test using your advice and I obtained better results on the edges. So I will look to this function to find the good parameters and maybe obtain good results for the faces.

Thanks for your answer.

Hello,

I looked at glPolygonOffset. With this function I need to know what to offset. In my case I do not know the geometry. But maybe I can know the sets of polygons which represent volumes.
So do you think that doing a very small different offset for each volume may be a solution ? For example :

inc=0.01; i=0;
for each volume
  glPolygonOffset(i, i);
  draw volume
  i = i+inc;
end for

Do you think that a simple solution like this exists ?

Thanks