如何更改 OpenGL 中的视角?

How do I change the viewing angle in OpenGL?

我需要创建一个 3d 立方体,到目前为止我已经创建了所有顶点但是当我 运行 程序时我只能看到立方体(或者我希望是立方体,我可以'tell) 从一张脸上看,所以它看起来像一个正方形。我想知道如何从上方查看我的立方体,这样我就可以检查它是否真的像我想要的那样。

我使用 glVertex3f 创建了 24 个顶点,但就像我说的,我无法判断它是否是立方体,因为我无法从默认角度以外的角度观察它。

我尝试下载 GLM,但我很困惑如何使用它来改变观看视角。

glEnable(GL_DEPTH_TEST);
    // Loop until the user closes the window
    while (!glfwWindowShouldClose(window))
    {
        // Render here
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glBegin(GL_QUADS);
        glColor3f(0.0f, 1.0f, 0.0f);
        glVertex3f(0.5f, 0.5f, 0.5f);
        glVertex3f(-0.5f, 0.5f, 0.5f);
        glVertex3f(-0.5f, -0.5f, 0.5f);
        glVertex3f(0.5f, -0.5f, 0.5f);

        ... // Repeating drawing the vertices for each vertex of the cube

        glEnd();

        // Swap front and back buffers
        glfwSwapBuffers(window);

        // Poll for and process events
        glfwPollEvents();
    }

没有错误消息,但我无法判断它是否是立方体。

    // Render here
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // need the window width & height to compute aspect ratio
    int width, height;
    glfwGetWindowSize(window, &width, &height);

    // set up the camera projection (if you haven't done this in init)
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, float(width) / height, 0.1f, 100.0f);

    // set camera position & orientation
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(1, 1, -3, //< eye position
              0, 0, 0,  //< aim position
              0, 1, 0); //< up direction

    // now draw stuff
    glBegin(GL_QUADS);
    glEnd();