我是openGL的新手,我正在努力学习基础知识。我已经创建了一个立方体的顶点及其EBO的索引,它应该是一个完美的立方体,这意味着所有方面的长度相同。但是我得到了这个: https://i.gyazo.com/1fb82be379da9b18133a0ab0da8ccbf4.png 这种矩形,不是方形脸。
顶点和索引如下:
std::vector<GLfloat> _Vertices = {
// Positions // Colors // Texture Coords
//Front
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, //0 Top Right
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, //1 Bottom Right
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, //2 Bottom Left
-0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, //3 Top Left
//Right
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, //4 Top left
0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, //5 Top right
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, //6 Bottom right
0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, //7 Buttom left
//Left
-0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, //8 Top Right
-0.5f, 0.5f,-0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, //9 Buttom Right
-0.5f, -0.5f,-0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, //10 Buttom Leff
-0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, //11 Top Left
//Top
-0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, //12 Buttom Left
-0.5f, 0.5f,-0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, //13 Top Left
0.5f, 0.5f,-0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, //14 Top Right
0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, //15 Buttom right
//Back
0.5f, 0.5f,-0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, //16 Top Right
0.5f, -0.5f,-0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, //17 Bottom Right
-0.5f, -0.5f,-0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, //18 Bottom Left
-0.5f, 0.5f,-0.5f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, //19 Top Left
//Buttom
-0.5f, -0.5f,-0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, //20 Top left
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, //21 Top Right
0.5f, -0.5f,-0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, //22 Buttom Right
-0.5f, -0.5f,-0.5f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f //23 Buttom Lrft
};
std::vector<GLuint> Indices = {
0, 1, 2, // Firs square
2, 3, 0,
4, 5, 6,
6, 7, 4,
8, 9, 10,
10, 11, 8,
12, 13, 14,
14, 15, 12,
16, 17, 18,
18, 19, 16,
20, 21, 22,
22, 23, 20
};
现在,如果您需要部分代码,请在评论部分询问。感谢。
答案 0 :(得分:5)
你的X和Y坐标范围从-0.5到0.5,但你的Z只有-0.5到0.0