我试图在我的程序中使用着色器,但我遇到了非常奇怪的错误...
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/