opengl将不会使用glm :: rotate进行渲染

时间:2018-07-09 19:12:05

标签: c++ opengl glm-math

在旋转模型视图时,opengl进行渲染时遇到一些问题。当我在不使用glm :: rotate或角度为0的情况下渲染下面的代码时,模型将正常渲染,但是当我将角度设置为非0时,模型将不会渲染。它们应该没有初始化问题,因为只有glm :: rotate使其无法呈现。这个问题可能从哪里来?

渲染代码:

    Gl_object::render(double rotation)
    {
        shader.use();
        glBindTexture(GL_TEXTURE_2D, m_texture);

        glBindVertexArray(m_VAO);


        glm::mat4 modelview = getModelview();
        modelview = glm::rotate(modelview, (float)rotation, glm::vec3(0, 0, 1)); 
        glm::mat4 modelviewProjection = getProjection() * modelview;
        shader.setMat4("modelviewProjection", modelviewProjection);
        glDrawArraysInstanced(GL_TRIANGLES, 0, 6, m_size);

        glBindVertexArray(0);
        glUseProgram(0);
        glBindTexture(GL_TEXTURE_2D, 0);
    }

片段着色器:

#version 330 core

in vec2 texCoord;

uniform sampler2D texture0;

out vec4 out_Color;

void main()
{
    out_Color = texture(texture0, texCoord);
}

顶点着色器:

#version 330 core

layout (location = 0) in vec3 in_Vertex;
layout (location = 1) in vec2 in_texCoord;
layout (location = 2) in vec3 in_Offset;

uniform mat4 modelviewProjection;

out vec2 texCoord;

void main()
{
    gl_Position = modelviewProjection * vec4(in_Vertex + in_Offset, 1.0);
    texCoord = in_texCoord;
}

0 个答案:

没有答案