python - PySide QGLBuffer 分配输入数据

标签 python qt opengl pyside

我正在尝试运行 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/

相关文章:

python - Pandas 按时间分组,指定开始时间(非整数分钟)

python - 什么取代了 text.latex.unicode?

qt - QML:无法将 [undefined] 分配给

android - 为 android 构建时出现 Qt 错误

c++ - glfwSetScrollCallback() 编译失败

python - Django:如何将用户与请求工厂相关联

python - 如何更快地找出 HTTP 状态?

opengl - 您可以使用单个 VBO 使用多个目标吗?

android - 如何仅在 .pro 文件中为 Android 平台构建指定库?

c++ - 如何通过鼠标移动使OpenGL相机在SFML中移动