OpenGL glm :: perspective()不能正常工作,对象不是3d

时间:2017-04-15 10:48:41

标签: c++ opengl glfw glm-math

这是我的游戏循环。我知道我不需要两次声明这些变量,但我只是为了以下情况做了它们:

while (!glfwWindowShouldClose(window))
    {


        GLfloat currentFrame = glfwGetTime();
        deltaTime = currentFrame - lastFrame;
        lastFrame = currentFrame;


        glfwPollEvents();


        glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glUseProgram(shaderProgram);
        glm::mat4 view;
        view = glm::rotate(view, 50.0f, glm::vec3(0.0f, 0.0f, 1.0f));
        glm::mat4 projection;
        projection = glm::perspective(-45.0f, float(WIDTH / HEIGHT), 0.1f, 100.0f);

        GLint modelLoc = glGetUniformLocation(shaderProgram, "model");
        GLint viewLoc = glGetUniformLocation(shaderProgram, "view");
        GLint projLoc = glGetUniformLocation(shaderProgram, "projection");

        glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
        glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection));

        glBindVertexArray(VAO);
        glm::mat4 model;
        model = glm::scale(model, glm::vec3(0.5f, 0.5f, 0.5f));
        glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
        glDrawArrays(GL_TRIANGLES, 0, 36);
        glBindVertexArray(0);

        glUseProgram(shaderProgram2);
        glm::mat4 view2;
        view2 = translate(view2, glm::vec3(0.0f, 0.0f, -0.6f));

        GLint modelLoc2 = glGetUniformLocation(shaderProgram2, "lightmodel");
        GLint viewLoc2 = glGetUniformLocation(shaderProgram2, "lightview");
        GLint projLoc2 = glGetUniformLocation(shaderProgram2, "lightprojection");

        glm::mat4 model2;
        model2 = glm::scale(model2, glm::vec3(0.5f, 0.5f, 0.5f));


        glUniformMatrix4fv(viewLoc2, 1, GL_FALSE, glm::value_ptr(view2));
        glUniformMatrix4fv(projLoc2, 1, GL_FALSE, glm::value_ptr(projection));

        glUniformMatrix4fv(modelLoc2, 1, GL_FALSE, glm::value_ptr(model2));

        glBindVertexArray(lightVAO);
        glDrawArrays(GL_TRIANGLES, 0, 36);
        glBindVertexArray(0);

        glfwSwapBuffers(window);
    }

这就是输出:

https://imgur.com/a/arEd7

我不清楚glm :: perspective()输入是否应该是弧度或度数,但我尝试了两者并且它们都给出了相同的放大,非3D结果。我不知道我在这里做错了什么。我正在根据this教程做这些。我的代码体看起来与我自己创建的一些类的教程保存完全相同。这可能是什么问题?

0 个答案:

没有答案