Backface culling works totally wrong

Started by
4 comments, last by xantier 10 years, 6 months ago

glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

I have been trying to implement deferred rendering for 2 weeks. But all of the meshes in my test program are culled reversely. The code above should be the correct way to render a model. Every example i looked at draws the objects like that. But here is the result when i use GL_BACK as cull face:

HFAyy.png

And this is the GL_FRONT:

kcIEq.png

GL_FRONT should have been the result i expected from GL_BACK. Strange thing is when I set glFrontFace to GL_CW, everything disappears. So this problem is not about winding. I spent all my day on searching information about this. Only thing i found is something about depth buffers. But I can't see any problems in creation. Just because of this problem, I can't correctly do stencil pass for spot light rendering. I enable GL_DEPTH_TEST in geometry pass. This is what i attach to my fbo as depth buffer


glGenRenderbuffers(1, &depthTexture);
glBindRenderbuffer(GL_RENDERBUFFER, depthTexture);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthTexture);

The main question is, what are the possibilities that would cause a reversed backface culling ?

Advertisement

Top of the suspect list should be your world/view/projection matrices. It's very easy to mess them up and accidentally make the world go inside out.

Top of the suspect list should be your world/view/projection matrices. It's very easy to mess them up and accidentally make the world go inside out.

All of them are glm:: matrices like glm::perspective etc. view matrix is built by glm::quats but i use fixed functionality for model matrix like glTranslate scale etc. and use gl_modelviewmatrix in glsl. if it is really about that, i can change things. but if not, i will have to stop developing my engine because this problem blocks me to advance further.

please someone help me. i am totally desperate right now. my faces are inversed and i have tried almost every possible combinations of perspective. just a hint, please.

Post your code, including the shaders.

i think i am about to solve this. as i posted setting front face to GL_CW was causing everything to disappear. this was because i applied the same rule in drawing full screen quad. so i have solved this part by disabling culling in the last part. so far so good, but the thing is why every mesh i load has clockwise vertex order ? actually this is not a problem since i totally solved the problem.

This topic is closed to new replies.

Advertisement