GL_CULL_FACE makes all objects disappear
Asked Answered
S

2

2

I am trying to create some simple polygons in openGL3.3. I have 2 types of objects with the following properties :

Object 1 - 10 vertices (listed below, in order) stored in GL_ARRAY_BUFFER and use GL_TRIANGLE_FAN

v x y z w  
v 0.0 0.0 1.0 1.0  
v 0.0 1.0 0.1 1.0  
v 0.71 0.71 0.1 1.0  
v 1.0 0.0 0.1 1.0  
v 0.71 -0.71 0.1 1.0  
v 0.0 -1.0 0.1 1.0  
v -0.71 -0.71 0.1 1.0  
v -1.0 0.0 0.1 1.0  
v -0.71 0.71 0.1 1.0  
v 0.0 1.0 0.1 1.0  

Object 2 - 4 vertices (listed below, in order) stored in GL_ARRAY_BUFFER and use GL_TRIANGLE_STRIP

v x y z w  
v 0.0 0.0 0.0 1.0  
v 0.0 1.0 0.0 1.0  
v 1.0 0.0 0.0 1.0  
v 1.0 1.0 0.0 1.0  

I load 64 Object1's and 4 Object2's. The Object2's are scaled using glm::scale(20, 20, 0).

When I try to render these with GL_CULL_FACE disabled but GL_DEPTH_TEST enabled with glDepthFunc(GL_LESS) everything works fine. As soon as I try to enable GL_CULL_FACE all I get is a blank window.

Some other useful information :
- Rendering order = 4 Object2's followed by 64 Object1's
- Camera - glm::lookAt(glm::vec3(0.0f, 0.0f, 50.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
- Perspective - glm::perspective(45.0f, 16.0f / 9.0f, 0.01f, 1000.0f);

I have been trying to figure out why GL_CULL_FACE doesn't work for the past couple of days but have no idea. Any help is much appreciated.

Seamanlike answered 22/3, 2012 at 22:6 Comment(0)
T
4

This is almost always due to polygon normal direction (right-hand rule of the three vertices of each triangle)

Try switching the direction using:

glCullFace(GL_BACK or GL_FRONT)

Some more reading here

Titular answered 22/3, 2012 at 22:15 Comment(0)
R
3

Which culling direction have you specified? When you create a polygon, you 'wind' the vertices either clockwise or counter-clockwise relative to the camera's view point, and you have to tell OpenGL which type it should cull.

As you're probably aware, back face culling is for hiding polys facing away from the camera, so if you have clockwise-wound faces, that means the verts are clockwise in order when facing the camera and counter-clockwise facing away, so you tell OpenGL to cull counter-clockwise polys.

I suspect that you're culling the polys you want to see: GL_BACK is the default so switching the mode to GL_FRONT should work. See the documentation for more info: http://www.opengl.org/sdk/docs/man/xhtml/glCullFace.xml

Redevelop answered 22/3, 2012 at 22:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.