1

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

Marc
  • 1,029
  • 1
  • 10
  • 27
  • I made a mistake in the commands that I posted. Edited them. I don't know if the solution is related to culling – Marc Feb 05 '20 at 10:43
  • Render the exterior faces with only the Z-buffer (glColorMask false), then render the interior faces normally (glColorMask true)? – user253751 Feb 05 '20 at 14:45

1 Answers1

2

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).

Rabbid76
  • 202,892
  • 27
  • 131
  • 174