ddl*_*ddl 0 c++ opengl shader glsl 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
Run Code Online (Sandbox Code Playgroud)
我认为问题在于文件读取,但在尝试了很多方法后,它仍然无法正常工作.
所以这是我的代码:
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;
}
Run Code Online (Sandbox Code Playgroud)
我的着色器:
// 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;
}
Run Code Online (Sandbox Code Playgroud)
你错过了in行尾的分号.
你有:
in vec3 vVertex
in vec3 vColor
Run Code Online (Sandbox Code Playgroud)
你应该有:
in vec3 vVertex;
in vec3 vColor;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2894 次 |
| 最近记录: |