Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x OpenGL着色器编译错误(C0000和C0206)(PyOpenGL)_Python 3.x_Opengl_Glsl_Pyopengl - Fatal编程技术网

Python 3.x OpenGL着色器编译错误(C0000和C0206)(PyOpenGL)

Python 3.x OpenGL着色器编译错误(C0000和C0206)(PyOpenGL),python-3.x,opengl,glsl,pyopengl,Python 3.x,Opengl,Glsl,Pyopengl,我对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() {

我对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))
当我运行程序时,出现以下错误:

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)
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)
起初,我认为我得到了这个错误,因为我没有解析字符串并取出新行指示符,但一旦我使用“replace”字符串函数取出这些指示符,我就得到了这个错误:

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)
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)

我甚至在解析字符串后尝试将其编码为ascii,但这似乎也不起作用

您的顶点着色器出现语法错误,请使用此修复错误重试:

#version 330

in vec4 position;

void main()
{
    gl_Position = position;
}
1) 你错过了“;”在vec4位置的
行中


2) 线
gl_位置=vec4(位置,1.0f)
试图创建第一个参数位置为vec4的vec4实例,该位置恰好是vec4。要修复它,您可以直接指定vec4位置,如
gl\u position=position或使用类似的
gl_Position=vec4(Position.xyz,1.0)

我在顶点着色器的第2行看到一个缺少的分号。而且
位置
已经是
vec4
,因此通过在末尾添加1.0转换为
vec4
没有意义。您可以使用
gl\u Position=Position或使第2行正好
处于vec3位置