Thread: [PyOpenGL-Users] Problems with glReadPixels
Brought to you by:
mcfletch
From: Dirk R. <di...@li...> - 2007-06-29 15:55:23
|
Hi everybody, we're trying to use glReadPixels with PyOpenGL, but we're running into exceptions: Traceback (most recent call last): File "/store/home/mukaissi/MetNetVis/MetNetVis/UI/graphdrawwidget.py", line 155, in mousePressEvent index=GL.glReadPixels(event.x,event.y,1,1,GL.GL_RGB,GL.GL_UNSIGNED_BYTE) File "/store/home/mukaissi/software/PyOpenGL-3.0.0a6/OpenGL/GL/images.py", line 279, in glReadPixels ctypes.c_void_p( arrayType.dataPointer(array)) ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: wrong type Adding a few prints to see the types of the involved variables they seem to be ok: array: [[[0 0 0]]] <type 'numpy.ndarray'> arrayType: <class 'OpenGL.arrays.arraydatatype.GLubyteArray'> <type '_ctypes.PointerType'> dataPointer: 20509152 <type 'long'> This is using 3.0.0a6 on an x86_64 (RHEL) system. Is anybody using glReadPixels successfully? What are we missing? Thanks Dirk |
From: Dirk R. <di...@li...> - 2007-06-29 15:53:06
|
Hi everybody, we're trying to use glReadPixels with PyOpenGL, but we're running into exceptions: Traceback (most recent call last): File "/store/home/mukaissi/MetNetVis/MetNetVis/UI/graphdrawwidget.py", line 155, in mousePressEvent index=GL.glReadPixels(event.x,event.y,1,1,GL.GL_RGB,GL.GL_UNSIGNED_BYTE) File "/store/home/mukaissi/software/PyOpenGL-3.0.0a6/OpenGL/GL/images.py", line 279, in glReadPixels ctypes.c_void_p( arrayType.dataPointer(array)) ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: wrong type Adding a few prints to see the types of the involved variables they seem to be ok: array: [[[0 0 0]]] <type 'numpy.ndarray'> arrayType: <class 'OpenGL.arrays.arraydatatype.GLubyteArray'> <type '_ctypes.PointerType'> dataPointer: 20509152 <type 'long'> This is using 3.0.0a6 on an x86_64 (RHEL) system. Is anybody using glReadPixels successfully? What are we missing? Thanks Dirk |
From: Mike C. F. <mcf...@vr...> - 2007-06-29 18:53:50
|
Dirk Reiners wrote: > Hi everybody, > > we're trying to use glReadPixels with PyOpenGL, but we're running into exceptions: > > Traceback (most recent call last): > File "/store/home/mukaissi/MetNetVis/MetNetVis/UI/graphdrawwidget.py", > line 155, in mousePressEvent > > index=GL.glReadPixels(event.x,event.y,1,1,GL.GL_RGB,GL.GL_UNSIGNED_BYTE) > File > "/store/home/mukaissi/software/PyOpenGL-3.0.0a6/OpenGL/GL/images.py", line > 279, in glReadPixels > ctypes.c_void_p( arrayType.dataPointer(array)) > ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: wrong > type > ... > This is using 3.0.0a6 on an x86_64 (RHEL) system. > > Is anybody using glReadPixels successfully? What are we missing? > I don't have any code that uses the un-decorated version. glReadPixelsub seems to work fine (at least, the OpenGLContext/tests/saveimage.py test works fine on my CVS-based version of PyOpenGL). That's on an AMD64 Gentoo machine. Code looks identical for the two versions of the function (other than a type being specified by default). If you have failing code I could pdb through it might be easier to track down the issue. One other thing, what versions of ctypes and numpy are you using? Good luck, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |
From: Dirk R. <di...@li...> - 2007-06-29 20:14:17
|
Hi Mike, thanks for the quick response. Mike C. Fletcher wrote: > > I don't have any code that uses the un-decorated version. > glReadPixelsub seems to work fine (at least, the > OpenGLContext/tests/saveimage.py test works fine on my CVS-based version > of PyOpenGL). That's on an AMD64 Gentoo machine. Code looks identical > for the two versions of the function (other than a type being specified > by default). > > If you have failing code I could pdb through it might be easier to track > down the issue. One other thing, what versions of ctypes and numpy are > you using? Gah! As it turns out Qt doesn't export the event's position as variables but as accessors, so the event.x and event.y that we passed in ReadPixels were functions, not positions. Fixing that fixed the error. Not exactly an intuitive failure mode, but that's Python for you. ;) But now I have some other questions concerning glReadPixels: I'm a little confused about the return types. Adding the following to cube.py:display data = glReadPixelsub(0, 0, 1, 1, GL_RGB) print data, type(data[0][0][0]) data = glReadPixelsb(0, 0, 1, 1, GL_RGB) print data, type(data[0][0][0]) data = glReadPixelsui(0, 0, 1, 1, GL_RGB) print data, type(data[0][0]) data = glReadPixelsi(0, 0, 1, 1, GL_RGB) print data, type(data[0][0]) data = glReadPixelsf(0, 0, 1, 1, GL_RGB) print data, type(data[0][0]) gives me [[[0 0 0]]] <type 'numpy.int8'> [[[0 0 0]]] <type 'numpy.int8'> [[0]] <type 'numpy.int32'> [[0]] <type 'numpy.int32'> [[ 0.]] <type 'numpy.float32'> Why do I get signed integers in each case? I would have expected unsigneds for the ub/ui cases. Why do I get only a 2D array for the i/ui/f cases? I would have expected the usual RGB triple. None of these are showstoppers, but they surprised me a bit. Thanks Dirk P.S.: Can you please close our bug? No clue why it showed up 5 times. |
From: Mike C. F. <mcf...@vr...> - 2007-07-01 03:44:26
|
Dirk Reiners wrote: ... > But now I have some other questions concerning glReadPixels: I'm a little > confused about the return types. Adding the following to cube.py:display > > data = glReadPixelsub(0, 0, 1, 1, GL_RGB) > print data, type(data[0][0][0]) > data = glReadPixelsb(0, 0, 1, 1, GL_RGB) > print data, type(data[0][0][0]) > data = glReadPixelsui(0, 0, 1, 1, GL_RGB) > print data, type(data[0][0]) > data = glReadPixelsi(0, 0, 1, 1, GL_RGB) > print data, type(data[0][0]) > data = glReadPixelsf(0, 0, 1, 1, GL_RGB) > print data, type(data[0][0]) > > gives me > > [[[0 0 0]]] <type 'numpy.int8'> > [[[0 0 0]]] <type 'numpy.int8'> > [[0]] <type 'numpy.int32'> > [[0]] <type 'numpy.int32'> > [[ 0.]] <type 'numpy.float32'> > > Why do I get signed integers in each case? I would have expected unsigneds for > the ub/ui cases. > It's a bug, I didn't realise that numpy had added unsigned versions of the int types so the code was doing the same as it did for Numeric. I've added support for them on my local machine, will push it out on the next alpha release. > Why do I get only a 2D array for the i/ui/f cases? I would have expected the > usual RGB triple. > You're getting all three colours in a single integer IIUC, that is, you're seeing an integer with bits 0-8 with colour 1, 1-16 with colour two etceteras. > P.S.: Can you please close our bug? No clue why it showed up 5 times. > Will do so when I sit down to work on the project. Take care, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |
From: Dirk R. <di...@li...> - 2007-07-01 15:53:30
|
Hi Mike, Mike C. Fletcher wrote: > > It's a bug, I didn't realise that numpy had added unsigned versions of > the int types so the code was doing the same as it did for Numeric. > I've added support for them on my local machine, will push it out on the > next alpha release. OK, great. > You're getting all three colours in a single integer IIUC, that is, > you're seeing an integer with bits 0-8 with colour 1, 1-16 with colour > two etceteras. I understand that, and I'm not saying it's a bad thing (actually, that's EXACTLY what we need right now ;), but it's not quite consistent with the regular OpenGL behavior and therefore somewhat unexpected. Would it make sense to have a different entry point for this behavior? Nonetheless, for the float I'm not sure how to use it. How would I split a single float into 4 pieces? Thanks for your help! Dirk |