Skip to content Skip to sidebar Skip to footer

Pyopengl. X = Glgetdoublev(gl_modelview_matrix) Returns Memory Address

I'm trying to store the location of a cube in the value x and when I try and print(x) instead of printing the location, it prints

Solution 1:

I really love people who provide answers that aren't noob-friendly.

Rafael Cardoso seems to expect you know how to use VBOs and such. (from your wording, I can assume you hardly know much about what you're doing)

I'm not too skilled with ctypes or OpenGL.arrays, (I just got into them last night trying to remove numpy from a GLSL 3D viewer) but from my python experience, what he's saying is you need to do something like:

from OpenGL import GL, arrays
x = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)
handler = arrays.ctypesarrays.CtypesArrayHandler()
print handler.asArray(x,typecode=None)

I can't really help because I have cruddy numpy installed which PyOpenGL recognizes... So for me, glGetDoublev(GL_MODELVIEW_MATRIX) returns a disgusting numpy.array() object rather than an OpenGL.arrays.ctypesarrays.c_double_Array_4_Array_4 object...

my tests with the above prints this:

>>> h = arrays.ctypesarrays.CtypesArrayHandler()
>>> x = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)
>>> x
array([[ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.]])
>>> h.asArray( x, ctypes.c_double )
array([[ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.]])

From the way it looks, it's not very useful.

EDIT: forgot about my VM, which has a python installation without numpy :)

same result though:

>>>from OpenGL import GL, arrays>>>h = arrays.ctypesarrays.CtypesArrayHandler()>>>x = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)>>>x
<OpenGL.arrays.lists.c_double_Array_4_Array_4 object at 0x015FEE90>
>>>h.asArray( x )
<OpenGL.arrays.lists.c_double_Array_4_Array_4 object at 0x015FEE90>

EDIT2: this works:

>>> [[ c for c in r] for r in x]
[[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]

you really don't even need to reformat as <OpenGL.arrays.lists.c_double_Array_4_Array_4 object at 0x015FEE90> is a 2D iterator. ;)

>>> for r in x: print r

<OpenGL.constants.c_double_Array_4 object at 0x01605CB0>
<OpenGL.constants.c_double_Array_4 object at 0x01605D50>
<OpenGL.constants.c_double_Array_4 object at 0x01605CB0>
<OpenGL.constants.c_double_Array_4 object at 0x01605D50>

another example:

>>> list(x)
[<OpenGL.constants.c_double_Array_4 object at 0x01605CB0>, <OpenGL.constants.c_double_Array_4 object at 0x01605D00>, <OpenGL.constants.c_double_Array_4 object at 0x01605DA0>, <OpenGL.constants.c_double_Array_4 object at 0x01605DF0>]

Post a Comment for "Pyopengl. X = Glgetdoublev(gl_modelview_matrix) Returns Memory Address"