无法获取属性位置 pyglet

Can't get attribute location pyglet

此代码不允许我使用它

 position_loc = glGetAttribLocation(shader, "position")
 color_loc = glGetAttribLocation(shader, "color")

附近的完整代码

 shader = OpenGL.GL.shaders.compileProgram(OpenGL.GL.shaders.compileShader(self.vertex_shader_source, GL_VERTEX_SHADER),
                                              OpenGL.GL.shaders.compileShader(self.fragment_shader_source, GL_FRAGMENT_SHADER))
                                              
    position_loc = glGetAttribLocation(shader, "position")
    color_loc = glGetAttribLocation(shader, "color")
                    
                                              
    glUseProgram(shader)
    
    vbo = GLuint(0)
    glGenBuffers(1, vbo)
    
    glBindBuffer(GL_ARRAY_BUFFER, vbo)
    glBufferData(GL_ARRAY_BUFFER, 72, (GLfloat * len(self.triangle))(* self.triangle), GL_STATIC_DRAW)
    
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 24, ctypes.c_void_p(0))
    glEnableVertexAttribArray(0)
    
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 24, ctypes.c_void_p(12))
    glEnableVertexAttribArray(1)

这是除着色器之外的所有代码,这是我的另一个问题。如果我没有得到位置,它工作正常,但我被告知我需要。如果你能帮助我理解为什么它不起作用那就太棒了

name 参数需要是 Bytes literal (bytesprefix b) 而不是字符串:

position_loc = glGetAttribLocation(shader, 'position')
color_loc = glGetAttribLocation(shader, 'color')

position_loc = glGetAttribLocation(shader, b'position')
color_loc = glGetAttribLocation(shader, b'color')