c++ - GLSL 语法错误 : "in" parse error

标签 c++ opengl glsl shader parse-error

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

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() + '\0';
        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;

关于c++ - GLSL 语法错误 : "in" parse error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20643919/

相关文章:

c++ - 使用几何着色器创建新的图元类型

c++ - 需要 Visual Studio 环境 2010 C++ 调试技术建议

c++ - 离散傅里叶变换实现给出与 OpenCV DFT 不同的结果

opengl - 3D投影映射

c++ - 替换 glaux 函数

opengl - #version 330 和#version 330 核心有什么区别?

c++ - OpenGL 4.3 错误地将第四个纹理坐标映射到与第三个纹理坐标相同的位置

java - 在 OpenGL ES 2.0 中绘制球体

c++ - 最佳实践 : syncing between threads

c++ - 让 visual studio 2012 自动复制引用项目的引用 (C++)