Python 如何正确使用QOpenGLBuffer';是否在PyQt5中分配/读取/写入?

Python 如何正确使用QOpenGLBuffer';是否在PyQt5中分配/读取/写入?,python,pyqt5,Python,Pyqt5,需要void*数据输入。所以,我让它和这样的东西一起工作 vbo = QtGui.QOpenGLBuffer(QtGui.QOpenGLBuffer.VertexBuffer) vrtxAttrs = [1., 1., 1., 0., 0.1, 0.1, 1.0, -1., -1., -1., 1.0, 0.9, 0.9, 1.0] # a list of interleaved positions xyz and colors rgba data = numpy.ar

需要void*数据输入。所以,我让它和这样的东西一起工作

vbo = QtGui.QOpenGLBuffer(QtGui.QOpenGLBuffer.VertexBuffer)
vrtxAttrs = [1., 1., 1., 0., 0.1, 0.1, 1.0,
             -1., -1., -1., 1.0, 0.9, 0.9, 1.0] # a list of interleaved positions xyz and colors rgba
data = numpy.array(vrtxAttrs, dtype=numpy.float32)
老实说,我不知道我是怎么来的。我尝试了很多方法,却无意中使用了
data.ctypes.data\u as(ctypes.POINTER(ctypes.c\u void\u p)).contents
。请告诉我这很糟糕,还有更好的办法

# How I allocate..
vbo.allocate(data.ctypes.data_as(ctypes.POINTER(ctypes.c_void_p)).contents,
                          sys.getsizeof(data))

这些Python文档是荒谬的,是的,我们知道如何在C++中使用它们,Python呢?首先,我在寻找解释这个答案可能不会赢得任何奖项的答案,它是在凌晨4:00匆忙完成的。嗯。。。这是我第一次看到有人使用PyQT,并且最终比使用C++时更复杂。这应该是一个奖品!你在我的回答中遗漏了什么?你知道,赏金和所有。。。必须选择我的答案作为“解决方案”,以使其按我的方式运送。时间到了,但我想“系统”(SO)足够聪明,当我回答时,它被接受后,我就知道还剩3个小时了。但是我倾向于高估人和他们创造的计算机系统的智能。我对如何在python中实现这一点感到非常困惑和不知所措。我已经像僵尸一样监视这篇文章好几天了,没有一个答案。大约两天前我放弃了。见鬼,我甚至梦见有人评论使用列表。这让我今天查看了邮件。谢谢,善良的陌生人!哈哈,所以有人比我更疯狂!就是这样!很抱歉,我直到现在才看到答案。不过我还是接受了答案

# How I write.. (I believe this calls glBufferSubData internally)
# I intend to change the second vertex's position and color.
newdata = [2., 2., 2., 0.5, 0.4, 0.4, 1.]
toWrite = numpy.array(newdata, dtype=numpy.float32)
offset = 1 * 7 * 4 # this has to be in bytes. (1 is the index, 7 the stride, 4 the bytesize.)
count = len(newdata) * 4 # this has to be in bytes.
vbo.write(offset, data.ctypes.data_as(ctypes.POINTER(ctypes.c_void_p)).contents, count)
# How I read,
# I don't read, since I don't know what weird cast I need to do to read.
# The usage is documented as bool QOpenGLBuffer::read(int offset, void *data, int count)