OpenGL render interior faces with occlusion

130 Views Asked by At

Is there a way in OpenGL to render only interior faces while exterior faces still cover/occlude the interior ones? To better understand what I want to accomplish, if I would slice a randomly positioned cylinder, I would see only an ellipse.

I have tried:

    glEnable(GL_CULL_FACE);
    glEnable(GL_BACK);

But in this case I see the whole interior of the cylinder, while the exterior faces just dissappear without covering anything.

Thanks

1

There are 1 best solutions below

0
On

GL_BACK can't be "enabled". The culled faces are selected by glCullFace:

glEnable(GL_BACK);

glCullFace(GL_BACK);

Note, glEnable(GL_BACK) will cause an INVALID_ENUM error.

Face culling depends on the winding order. See also Face Culling.

e.g. If your faces are clockwise and you want to cull the back faces, then you have to:

glFrontFace(GL_CW​);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);

Note, it is important, that all the faces have the same winding order (clockwise or counter clockwise).