0

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

genpfault
  • 51,148
  • 11
  • 85
  • 139
Lurern
  • 21
  • 3
  • 1
    Face culling is based on the winding order of triangles. And since we can't see your triangles, for all we know, they all appear to use the same order. Provide a [mcve]. – Nicol Bolas May 24 '17 at 19:43
  • Well it can't really be the winding when `GL_FRONT` works perfectly, can it? And even if the winding was bad it would have rendered _something_? Added winding to the question. – Lurern May 24 '17 at 19:50
  • just a guess but if you are using directional lights and no ambient then rendered back faces would be black ... unless you use double sided lighting computations. – Spektre May 25 '17 at 09:16
  • Removing the light calculations and just doing `fragColor = texture(tex, texCoordV)` in the shader didn't change anything (apart from removing the lights, obviously) – Lurern May 25 '17 at 10:41

1 Answers1

1

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.

Ilias Kap
  • 26
  • 1