PySide QGLBuffer allocate input data
-
I'm trying to run PySide version of OpenGL Core Profile Qt demo - How_to_use_OpenGL_Core_Profile_with_Qt.
It uses QGLBuffer.allocate() method (C++ code)
@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 way will be:
@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)@But when I run this code I get following error
@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)
@I found unit test that is used for this functionality - it uses QByteArray.
@data = QByteArray("12345")
b.allocate(data)@But I don't understand how to convert Python list to QByteArray or use allocate with list. Or is it a bug in PySide wrapper function?
-
It seems I found solution. We should use python modules like struct or array. For example:
@from array import *
points = [0.5, 1, -0.5]
data = array('f', points)data.tostring() - returns packed data with size of len(data.tostring())@