I'm still pretty new to opengl and i'm trying to compile my vertex and fragment shader but keep getting an error. Heres the shaders i'm compiling:
我对opengl还是很陌生的,我正在尝试编译我的顶点和片段着色器,但不断出错。我正在编译的着色器:
# Vertex shader
vert_shader = """
#version 330
in vec4 position
void main()
{
gl_Position = vec4(position, 1.0f);
}
"""
# Fragment shader
frag_shader = """
#version 330
void main()
{
gl_FragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);
}
"""
# Compiles the vertex and fragment shader
shader = OpenGL.GL.shaders.compileProgram(OpenGL.GL.shaders.compileShader(str(vert_shader), GL_VERTEX_SHADER),
OpenGL.GL.shaders.compileShader(str(frag_shader), GL_FRAGMENT_SHADER))
When i run my program, i get this error:
当我运行程序时,我得到这个错误:
RuntimeError: ('Shader compile failure (0): b\'0(4) : error C0000: syntax error, unexpected reserved word "void", expecting \\\',\\\' or \\\';\\\' at token "void"\\n\'', [b'\n #version 330\n in vec4 position\n void main()\n {\n gl_Position = vec4(position, 1.0f);\n }\n\n '], GL_VERTEX_SHADER)
Initially i thought i was getting this error because i didn't parse the string and take out the new line indicators, but once i took those out using the 'replace' string function, i got this error:
最初,我以为我得到了这个错误,因为我没有解析字符串并取出新的行指示器,但是一旦我用“替换”字符串函数取出这些,我就得到了这个错误:
RuntimeError: ('Shader compile failure (0): b\'0(1) : error C0205: invalid profile "in"\\n0(1) : error C0206: invalid token "vec4" in version line\\n\'', [b' #version 330 in vec4 position void main() { gl_Position = vec4(position, 1.0f); } '], GL_VERTEX_SHADER)
I even tried encoding the string as ascii after parsing it but that didn't seem to work either.
我甚至尝试在解析后将字符串编码为ascii,但这似乎也不起作用。
1 个解决方案
#1
0
Your vertex shader had syntax errors, try again with this fixed one:
你的顶点着色器有语法错误,再试试这个固定的:
#version 330
in vec4 position;
void main()
{
gl_Position = position;
}
1) You were missing ';' in the line in vec4 position
你失踪了,在vec4的位置。
2) Line gl_Position = vec4(position, 1.0f);
was trying to create a vec4 instance with the first argument position, which happens to be a vec4. To fix it you can just assigning directly the vec4 position like gl_Position = position;
or using swizzling like gl_Position = vec4(position.xyz, 1.0);
2)Line gl_Position = vec4(位置,1.0f);尝试用第一个参数位置创建一个vec4实例,它恰好是一个vec4。要修复它,您可以直接指定vec4位置,比如gl_Position =位置;或者使用像gl_Position = vec4(位置)这样的旋转。xyz,1.0);
#1
0
Your vertex shader had syntax errors, try again with this fixed one:
你的顶点着色器有语法错误,再试试这个固定的:
#version 330
in vec4 position;
void main()
{
gl_Position = position;
}
1) You were missing ';' in the line in vec4 position
你失踪了,在vec4的位置。
2) Line gl_Position = vec4(position, 1.0f);
was trying to create a vec4 instance with the first argument position, which happens to be a vec4. To fix it you can just assigning directly the vec4 position like gl_Position = position;
or using swizzling like gl_Position = vec4(position.xyz, 1.0);
2)Line gl_Position = vec4(位置,1.0f);尝试用第一个参数位置创建一个vec4实例,它恰好是一个vec4。要修复它,您可以直接指定vec4位置,比如gl_Position =位置;或者使用像gl_Position = vec4(位置)这样的旋转。xyz,1.0);