我在运行glGetUnfiormLocation调用时遇到问题。在运行ATI图形卡的学校计算机上构建项目时,该程序可以正常运行。但是,使用运行nvidia卡的学校计算机,对glGetUniformLocation的调用返回-1。

//c++ side
glLinkProgram(ShaderIds[0]);
ExitOnGLError("ERROR: Could not link the shader program");

ModelMatrixUniformLocaion = glGetUniformLocation(ShaderIds[0], "ModelMatrix");
ViewMatrixUniformLocation = glGetUniformLocation(ShaderIds[0], "ViewMatrix");
ProjectionMatrixUniformLocation = glGetUniformLocation(ShaderIds[0], "ProjectionMatrix");

ExitOnGLError("ERROR: Could not get the shader uniform locations");

这是顶点着色器
    layout(location=0) in vec4 in_Position;
    layout(location=1) in vec4 in_Color;
    layout(location=2) in vec2 in_Coord;

    uniform mat4 ModelMatrix;
    uniform mat4 ViewMatrix;
    uniform mat4 ProjectionMatrix;

    varying vec2 v_UVCoord;
    out vec4 ex_Color;

    void main(void)
    {
        gl_Position = (ProjectionMatrix * ViewMatrix * ModelMatrix) * in_Position;
        gl_PointSize = in_Coord.x;
        ex_Color = in_Color;
        v_UVCoord = in_Coord;
    }

据我所知,基于制服的优化,我不应该给我-1,因为它们和属性一样都在使用中。任何对此事的见识将不胜感激。

最佳答案

链接OpenGL程序失败时不会给出OpenGL错误。您必须actually check to see if the program linked properly

09-08 10:09