Lurern
Lurern

Reputation: 21

Face culling works with GL_FRONT, but not GL_BACK

I've enabled face culling with glEnable(GL_CULL_FACE), and I'm trying to cull the back faces, but whenever I do glCullFace(GL_BACK) nothing gets rendered.

If I do glCullFace(GL_FRONT) it works as expected (that is, renders the inside of my cubes, but not the outside).

I've tried to change the winding, but it doesn't seem to be that since GL_FRONT works.

What could be the reason for this?

It is rendered to a framebuffer with a depth renderbuffer enabled, if that matters. Disabling culling makes everything render as expected.

Edit

The winding used is counter-clockwise, i.e. the nearest side:

x, y, z

0, 0, 0
1, 0, 0
1, 1, 0

0, 0, 0
1, 1, 0
0, 1, 0

Here is an image of what it looks like with GL_FRONT:

with GL_FRONT

(without the back of the cubes, so you can see the effect). Again, this is what I expected it to look like.

And what it looks like without culling:

without culling

Upvotes: 0

Views: 1516

Answers (1)

Ilias Kap
Ilias Kap

Reputation: 26

I would like to share my experience since I had the same problem: I was able to render something with glCullFace(GL_FRONT) and get the clear color only with glCullFace(GL_BACK). Turns out that OpenGL was working perfectly fine (of course) and the problem was from the shading technique I used, Deferred Shading.

I was using a Quad in normalized device coordinates to show the result of the lighting calculations and this quad was in clockwise order! So, swaping the order of this quad, everything worked.

And this expands to everyone that projects something on the screen using a quad! Either disable culling before drawing it and then enable it again (don't recommend due to API calls) or simply make sure that the quad is defined in CCW.

Upvotes: 1

Related Questions