Re: Format of New glReadPixels

"Mike C. Fletcher" <[email protected]> Fri, 05 Jul 2013 17:03:24 -0400
Newsgroups gmane.comp.python.opengl.user
Message-ID <[email protected]>
On 13-06-29 06:44 PM, Ian Mallett wrote:
> Hi,
>
> The return value of glReadPixels seems to have changed since Py 2.5. 
> To take a screenshot, one used to be able to go:
> data = glReadPixels(0,0,screen_size[0],screen_size[1], GL_RGB, 
> GL_UNSIGNED_BYTE)
> image = pygame.image.fromstring(data,screen_size,"RGBA",True)
> pygame.image.save(image,"screenshot.png")
>
> This doesn't work anymore. It returns some data type that seems to 
> encapsulate a 3D array. I wasn't able to track down where this 
> datatype was defined. My best effort to reverse engineer it was 
> unsuccessful (the output is garbled):
> data = glReadPixels(0,0,screen_size[0],screen_size[1], GL_RGB, 
> GL_UNSIGNED_BYTE)
> r,g,b = data[0],data[1],data[2]
> image = pygame.Surface(screen_size)
> for y in range(screen_size[1]):
>     for x in range(screen_size[0]):
> image.set_at((x,screen_size[1]-y-1),(r[y][x],g[y][x],b[y][x]))
> pygame.image.save(image,"screenshot.png")
>
> What is the return value format of glReadPixels?
Apparently ctypes arrays no longer have .raw attributes, so if you don't 
have numpy the object wasn't being converted to a string. Weird thing is 
I don't see any documentation on .raw on arrays, so it's possible it was 
just working by fluke-of-implementation before.  I've added code that 
does the transformation of a ctypes array to the OpenGL/images.py module 
in bzr.

HTH,
Mike

-- 
________________________________________________
   Mike C. Fletcher
   Designer, VR Plumber, Coder
   http://www.vrplumber.com
   http://blog.vrplumber.com


------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
PyOpenGL Homepage
http://pyopengl.sourceforge.net