我目前正在使用OpenGL和GLM使用python开发FPS风格的相机模块。使用glm,我用gluLookAt()
生成视图矩阵。当我尝试使用glm.value_ptr()
将其加载到OpenGL时,它返回错误:
AttributeError: ("'CtypesPointerHandler' object has no attribute 'arrayByteCount'", <function asArrayTypeSize.<locals>.asArraySize at 0x0000021D3BD0CD08>)
这是我的代码:
viewMatrix = glm.lookAt(self.position, self.position + self.front, self.upVector)
glMatrixMode(GL_MODELVIEW)
glLoadMatrixf(glm.value_ptr(viewMatrix))
[请告诉我我做错了什么,也许可以解释一下glm.value_ptr()
到底返回了什么?预先感谢!
使用PyOpenGL时,必须将矩阵转换为列表。参见PyOpenGL - glLoadMatrix
:
glLoadMatrix
viewMatrix = glm.lookAt(self.position, self.position + self.front, self.upVector)
或者matList = [viewMatrix[i][j] for i in range(4) for j in range(4)]
glMatrixMode(GL_MODELVIEW)
glLoadMatrixf(matList)
接受glLoadMatrix
数组。参见ctypes.c_float
例如:
ctypes.c_float
甚至可以使用ctypes - Data types
matArray = (ctypes.c_float *16).from_buffer(viewMatrix)
glMatrixMode(GL_MODELVIEW)
glLoadMatrixf(matArray)