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
<OpenGL.arrays.ctypesarrays.c_double_Array_4_Array_4 object at 0x043E63A0>
Extra Info:
Windows 8.1 64-Bit
Python 3.4.3 32-Bit
PyOpenGL 3.1.1 32-Bit
PyGame 32-Bit (Can't find the version)
I have admin perms on my PC and the install of PyOpenGL and PyGame seemed to go ok. Thanks. If there's anythin else you would like to see e.g. the full code for my script, just ask.
EDIT:
This question is no longer needing an answer as I've moved on from this. Thanks to all who tried to help out, you're all amazing people for giving your time to do so.
If you want to get the dimensions of this object, you should not use print
as __str__()
or __repr()__
methods were not overwritten.
According to the Docs , for OpenGL.arrays.ctypesarrays
arrays, you should use CtypesArrayHandler
handler to extract information, such as dimensions(self, typeCode=None)
or view it as an array instead of an object (using asArray(self, value, typecode=None)
).
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>]
I just had the same problem today, even though this is an old thread. Installing Numpy solved the problem. I guess that's what Tcll
said at the beginning, but I only realized this after I solved the problem.