Re: [PyOpenGL-Users] best way to set up matrices and vertex arrays?
Brought to you by:
mcfletch
From: Dan H. <Dan...@no...> - 2010-03-09 18:14:08
|
Kolja Kaehler wrote: > Does anyone here have some advice for me on these matters? Maybe I am > just missing “the obvious way” to organize these things. Hi Kolja, I haven't had any problems using NumPy's row-major arrays with PyOpenGL. For instance if you have a row-major NumPy array of dtype [ ( "x", np.float32 ), ( "y", np.float32 ) ], you can pass the array directly to PyOpenGL by putting it in a vertex buffer object and then using glVertexPointer( 2, gl.GL_FLOAT, 0, None ) to tell GL to expect 2 floats for each vertex. The same principle works for 3D as well. And if you'd like to store several pieces of NumPy array data together, then you can just use a recarray, and then pass an individual "member" array to PyOpenGL at any point you want. Perhaps you can give an example of what you're trying to do where the row-major/column-major distinction gets in the way? There really isn't a good way to dynamically grow a vertex array with NumPy. Some options are: * Use numpy.resize(), which just returns a new, larger array copy. * Use numpy.ndarray.resize(), which can only resize if there are no other references to the array. * Accumulate and grow with a data structure other than a NumPy array, and then convert to a NumPy array when you're done growing. Some candidates are a Python list (slow), or if you're willing to use Cython or C, then accumulate in a C array with realloc() for growing. I haven't really used NumPy matrices, so I'll let someone else comment on that one. Dan |