gpt4 book ai didi

python - PySide QGLBuffer 分配输入数据

转载 作者:行者123 更新时间:2023-12-01 05:54:02 24 4
gpt4 key购买 nike

我正在尝试运行 PySide 版本的 OpenGL Core Profile Qt 演示 - How_to_use_OpenGL_Core_Profile_with_Qt .

它使用 QGLBuffer.allocate() 方法(C++ 代码)

float points[] = { -0.5f, -0.5f, 0.0f, 1.0f,
0.5f, -0.5f, 0.0f, 1.0f,
0.0f, 0.5f, 0.0f, 1.0f };
m_vertexBuffer.allocate( points, 3 * 4 * sizeof( float ) );

Pythonic 方式将是:

points = [-0.5, -0.5, 0.0, 1.0,
0.5, -0.5, 0.0, 1.0,
0.0, 0.5, 0.0, 1.0]
m_vertexBuffer.allocate(points)

但是当我运行此代码时,出现以下错误

TypeError: 'PySide.QtOpenGL.QGLBuffer.allocate' called with wrong argument types:
PySide.QtOpenGL.QGLBuffer.allocate(list)
Supported signatures:
PySide.QtOpenGL.QGLBuffer.allocate(void, int = -1)
PySide.QtOpenGL.QGLBuffer.allocate(int)

我找到了unit test用于此功能 - 它使用 QByteArray。

data = QByteArray("12345")
b.allocate(data)

但我不明白如何将Python列表转换为QByteArray或使用allocate with list。或者是 PySide 包装函数中的错误?

最佳答案

看来我找到了解决方案。我们应该使用 struct 或 array 等 Python 模块。例如:

from array import *

points = [0.5, 1, -0.5]
data = array('f', points)
# data.tostring() - returns packed data with size of len(data.tostring())

关于python - PySide QGLBuffer 分配输入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13315910/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com