简体   繁体   中英

OpenGL not making a perfect cube

I am new to openGL and I am trying to learn the basics. I've created the vertices of a cube and their indices for the EBO, it supposed to be a perfect cube, that means, the same length in all sides. However I get this: https://i.gyazo.com/1fb82be379da9b18133a0ab0da8ccbf4.png This kind of a rectangle, istead of a square face.

The vertices and the indices are the following:

    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
};

Now, if you need a part of the code, please ask in the comment section. Thanks.

你的 X 和 Y 坐标范围从 -0.5 到 0.5,但你的 Z 只有 -0.5 到 0.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM