GLSL 语法错误:"in"分析错误



我正在尝试在我的程序中使用着色器,但我遇到了非常奇怪的错误......

Vertex shader failed to compile with the following error
ERROR: 0:6: error(#132) Syntax error: "in" parse error
ERROR: error(#273) 1 compilation errors.  No code generated

我认为问题出在文件读取上,但是在尝试了许多方法之后,它仍然不起作用。

所以这是我的代码:

bool ShaderProgram::LoadShaderFile(const char* shader_path, GLuint& shader_id)
{
    ifstream oFileStream(shader_path);
    if(oFileStream)
    {
        // Load shader code
        string sShaderSource;
        sShaderSource.assign((istreambuf_iterator<char> (oFileStream) ), istreambuf_iterator<char> () );
        // Forward shader code to OGL
        const GLchar* chShaderSource = sShaderSource.c_str() + '';
        printf("%s", chShaderSource);
        glShaderSource(shader_id, 1, (const GLchar**) &chShaderSource, NULL);

        return true;
    }
    else
        return false;
}

还有我的着色器:

// shader.vs
// Vertex Shader
#version 330
in vec3 vVertex
in vec3 vColor
smooth out vec4 vVaryingColor;
void main()
{
    vVaryingColor = vec4(vColor, 1.0);
    gl_Position = vec4(vVertex, 1.0);
}

// shader.fs
// Fragment Shader
#version 330
smooth in vec4 vVeryingColor;
out vec4 vVaryingColor;
void main()
{
    vFragColor = vVaryingColor;
}

您缺少in行末尾的分号。

你有:

in vec3 vVertex
in vec3 vColor

您应该具备:

in vec3 vVertex;
in vec3 vColor;

相关内容

最新更新