问题描述
此代码不允许我使用它
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,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')