解析我的mat4变换矩阵到我的opengl着色器时遇到麻烦

trouble parsing my mat4 transformation matrix into my opengl shader?

本文关键字:我的 遇到 麻烦 opengl mat4 变换      更新时间:2023-10-16

我得到的错误信息是:

ERROR: 0:5: error<#12>> Unexpected qualifier
ERROR: 0:5: error<#12> Syntax error: "in_transformation" parse error
ERROR: error<#273> 2 compilation errors. No code generated

这是我的绘图函数,我将变换矩阵解析为着色器。我不确定这应该在这里,这应该在初始化函数中我在顶点数组中进行解析吗?矩阵?

    void Mesh3D::Draw()
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        // Draw elements of each mesh in the vector
        glm::mat4 matrix = matrixViewProjection*this->matrixModel;
        int loc = glGetUniformLocation(program, "in_transformation");
        glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(matrix));
        for (int i = 0; i<nVectorGeometry; i++)
        {
            glBindVertexArray(vaos[i]);
            glDrawElements(col->vectorGeometry[i].primitive
            col->vectorGeometry[i].index_count,
            GL_UNSIGNED_SHORT, col->vectorGeometry[i].indices);
        }
        glBindVertexArray(0);
        glutSwapBuffers();
    }

这是我的顶点着色器,因为我把它存储在头文件中注意,这一切都没有在转换矩阵中解析,所以问题与我如何存储着色器无关

static std::string  shaderVert = "#version 330n"
"in vec3 in_coords;n"
"in vec3 in_normals;n"
"in vec4 in_colors; n"//added by me
"in map4 in_transformation;n"//added by me
"out vec3 vertex_normal;n"
"out vec4 vertex_color;n"
"void main(void) {n"
"vertex_normal = in_normals;n"
"vertex_color = in_colors;n"//added by me
"gl_Position =in_transformation* vec4(in_coords, 1.0);n"
"}n";

谢谢,我不确定我是否正在设置变换矩阵正确:/?

这是我的变换矩阵的格式:
static glm::mat4 matrix =
{ 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };

你的变换变量在着色器中不是一个"统一"的变量。它的类型是map4,你确定你不是指mat4吗?

可以声明为

uniform mat4 transformation;

然后你可以得到位置并解析它

另外,考虑从文件中读取着色器,这样你就不必在每行末尾显式地添加换行符。我知道它是这样工作的,但它更容易为你写你的着色器

相关文章: