人脸剔除——隐藏立方体中所有不是正面的人脸
Face culling - Hide all the faces that are not front-faces in a cube
我想丢弃立方体中所有非正面的面,命令 glEnable(GL_CULL_FACE);
对我不起作用。这是我的立方体坐标
private float cubeCoords[] = {
-0.25f, 0.25f, 0.25f, // front top left 0
-0.25f, -0.25f, 0.25f, // front bottom left 1
0.25f, -0.25f, 0.25f, // front bottom right 2
0.25f, 0.25f, 0.25f, // front top right 3
-0.25f, 0.25f, -0.25f, // back top left 4
0.25f, 0.25f, -0.25f, // back top right 5
-0.25f, -0.25f, -0.25f, // back bottom left 6
0.25f, -0.25f, -0.25f};
drawOrder 是:
private short drawOrder[] = {
0, 1, 2, 0, 2, 3,//front
0, 4, 5, 0, 5, 3, //Top
0, 1, 6, 0, 6, 4, //left
3, 2, 7, 3, 7 ,5, //right
1, 2, 7, 1, 7, 6, //bottom
4, 6, 7, 4, 7, 5};
当立方体旋转时,我可以在立方体上看到背景中的一张脸。
感谢
当您使用 Face Culling then you've to respect the winding order. If face culling is enabled, then by defualt backfaces are culled, if the winding order of the faces is counter-clockwise. See glFrontFace
respectifely glCullFace
.
从左上角开始按逆时针顺序从前到后排序顶点:
private float cubeCoords[] = {
-0.25f, 0.25f, 0.25f, // front top left 0
-0.25f, -0.25f, 0.25f, // front bottom left 1
0.25f, -0.25f, 0.25f, // front bottom right 2
0.25f, 0.25f, 0.25f, // front top right 3
-0.25f, 0.25f, -0.25f, // back top left 4
-0.25f, -0.25f, -0.25f, // back bottom left 5
0.25f, -0.25f, -0.25f, // back top right 6
0.25f, 0.25f, -0.25f // back bottom right 7
};
正确的逆时针三角形面是:
private short drawOrder[] = {
0, 1, 2, 0, 2, 3, // front
4, 0, 3, 4, 3, 7, // top
5, 1, 0, 5, 0, 4, // left
7, 3, 2, 7, 2 ,6, // right
1, 5, 6, 1, 6, 2, // bottom
7, 6, 5, 7, 5, 4 // back
};
请注意,您必须以这种方式定义面,当您从立方体(网格)的 "outside" 观察它时,缠绕顺序是逆时针的。
我想丢弃立方体中所有非正面的面,命令 glEnable(GL_CULL_FACE);
对我不起作用。这是我的立方体坐标
private float cubeCoords[] = {
-0.25f, 0.25f, 0.25f, // front top left 0
-0.25f, -0.25f, 0.25f, // front bottom left 1
0.25f, -0.25f, 0.25f, // front bottom right 2
0.25f, 0.25f, 0.25f, // front top right 3
-0.25f, 0.25f, -0.25f, // back top left 4
0.25f, 0.25f, -0.25f, // back top right 5
-0.25f, -0.25f, -0.25f, // back bottom left 6
0.25f, -0.25f, -0.25f};
drawOrder 是:
private short drawOrder[] = {
0, 1, 2, 0, 2, 3,//front
0, 4, 5, 0, 5, 3, //Top
0, 1, 6, 0, 6, 4, //left
3, 2, 7, 3, 7 ,5, //right
1, 2, 7, 1, 7, 6, //bottom
4, 6, 7, 4, 7, 5};
当立方体旋转时,我可以在立方体上看到背景中的一张脸。
感谢
当您使用 Face Culling then you've to respect the winding order. If face culling is enabled, then by defualt backfaces are culled, if the winding order of the faces is counter-clockwise. See glFrontFace
respectifely glCullFace
.
从左上角开始按逆时针顺序从前到后排序顶点:
private float cubeCoords[] = {
-0.25f, 0.25f, 0.25f, // front top left 0
-0.25f, -0.25f, 0.25f, // front bottom left 1
0.25f, -0.25f, 0.25f, // front bottom right 2
0.25f, 0.25f, 0.25f, // front top right 3
-0.25f, 0.25f, -0.25f, // back top left 4
-0.25f, -0.25f, -0.25f, // back bottom left 5
0.25f, -0.25f, -0.25f, // back top right 6
0.25f, 0.25f, -0.25f // back bottom right 7
};
正确的逆时针三角形面是:
private short drawOrder[] = {
0, 1, 2, 0, 2, 3, // front
4, 0, 3, 4, 3, 7, // top
5, 1, 0, 5, 0, 4, // left
7, 3, 2, 7, 2 ,6, // right
1, 5, 6, 1, 6, 2, // bottom
7, 6, 5, 7, 5, 4 // back
};
请注意,您必须以这种方式定义面,当您从立方体(网格)的 "outside" 观察它时,缠绕顺序是逆时针的。