问题描述
我正在尝试在 openGL3.3 中创建一些简单的多边形.我有两种具有以下属性的对象:
I am trying to create some simple polygons in openGL3.3. I have 2 types of objects with the following properties :
对象 1 - 10 个顶点(按顺序在下面列出)存储在 GL_ARRAY_BUFFER
中并使用 GL_TRIANGLE_FAN
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
对象 2 - 4 个顶点(按顺序在下面列出)存储在 GL_ARRAY_BUFFER
中并使用 GL_TRIANGLE_STRIP
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
我加载了 64 个 Object1 和 4 个 Object2.Object2 使用 glm::scale(20, 20, 0)
缩放.
I load 64 Object1's and 4 Object2's. The Object2's are scaled using glm::scale(20, 20, 0)
.
当我尝试在 GL_CULL_FACE
禁用但 GL_DEPTH_TEST
与 glDepthFunc(GL_LESS)
启用的情况下渲染这些时,一切正常.一旦我尝试启用 GL_CULL_FACE
,我得到的只是一个空白窗口.
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.
其他一些有用的信息:
- 渲染顺序 = 4 个对象 2,然后是 64 个对象 1
- 相机 - glm::lookAt(glm::vec3(0.0f, 0.0f, 50.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0)f, 0.0f));
- 透视图 - glm::perspective(45.0f, 16.0f/9.0f, 0.01f, 1000.0f);
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);
过去几天我一直试图弄清楚为什么 GL_CULL_FACE
不起作用,但我不知道.非常感谢任何帮助.
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.
推荐答案
这几乎总是由于多边形法线方向(每个三角形的三个顶点的右手定则)
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 或 GL_FRONT)
glCullFace(GL_BACK or GL_FRONT)
更多阅读这里
这篇关于GL_CULL_FACE 使所有对象消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!