有人可以帮助 pyopengl 中的顶点着色器错误吗

Can someone help vertex shader error in pyopengl

我挑出了导致错误的这段代码

    self.vertex_shader_source = """
    #version 130
    in layout (location = 0) vec3 position;
    in layout (location = 1) vec3 color;
            
    out vec3 newColor;
    void main()
    {
        gl_Position = vec4(position, 1.0f);
        newColor = color;
    }
    """
    
    self.fragment_shader_source = """
    #version 130
    in vec3 newColor;
    
    out vec4 outColor;
    void main()
    {
        outColor = vec4(newColor, 1.0f);
    }
    """

错误

Traceback (most recent call last):
File "/home/awesomenoob/Coding/Python/Rendering/Opengl-tri.py", line 23, in <module>
window = MyWindow(1280, 720, "yoot", resizable=True)
File "/home/awesomenoob/Coding/Python/Rendering/Opengl-tri.py", line 10, in __init__
self.triangle = Triangle()
File "/home/awesomenoob/Coding/Python/Rendering/Triangle.py", line 35, in __init__
shader = 
OpenGL.GL.shaders.compileProgram(OpenGL.GL.shaders.compileShader(self.vertex_shader_source, GL_VERTEX_SHADER),
File "/home/awesomenoob/.local/lib/python3.7/site-packages/OpenGL/GL/shaders.py", line 241, in compileShader
shaderType,
OpenGL.GL.shaders.ShaderCompilationError: ('Shader compile failure (0): b"0:3(12): error: 
syntax error, unexpected \'(\', expecting \'{\'\n"', [b'\n        #version 130\n        in 
layout (location = 0) vec3 position;\n        in layout (location = 1) vec3 color;\n                
\n        out vec3 newColor;\n        void main()\n        {\n            gl_Position = 
vec4(position, 1.0f);\n            newColor = color;\n        }\n        '], 35633)

如果你能帮助我理解我做错了什么,那将是一个巨大的帮助。我只是想在 python

中学习 pyglet/opengl

顶点着色器属性位置Layout qualifiers are supported since GLSL Version 3.30. Compare OpenGL Shading Language 1.30 Specification and OpenGL Shading Language 3.30 Specification。如果可能,请使用 GLSL 3.00。

或者删除布局限定符:

#version 130
in vec3 position;
in vec3 color;
        
out vec3 newColor;
void main()
{
    gl_Position = vec4(position, 1.0f);
    newColor = color;
}

链接程序后用glBindAttribLocation before the program is linked or get the attribute locations with glGetAttribLocation设置属性位置。

例如:

shader = OpenGL.GL.shaders.compileProgram(...)
position_loc = glGetAttribLocation(shader, b'position')
color_loc = glGetAttribLocation(shader, b'color')