[ pyopengl-Bugs-1959860 ] glReadPixels breaks 2.x compat. breaks pygame.

"SourceForge.net" <[email protected]> Fri, 13 Jun 2008 09:33:10 -0700
Newsgroups gmane.comp.python.opengl.devel
Message-ID <[email protected]>
Bugs item #1959860, was opened at 2008-05-07 19:08
Message generated for change (Comment added) made by mcfletch
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105988&aid=1959860&group_id=5988

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: GL
Group: v3.0.0
Status: Open
Resolution: Wont Fix
Priority: 5
Private: No
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Mike C. Fletcher (mcfletch)
Summary: glReadPixels breaks 2.x compat.  breaks pygame.

Initial Comment:
Hi,

with glReadPixels changing its interface from 1, 2.x, it breaks pygame.image.save(screen).


This is the only pyopengl function that pygame uses.  

It would be nice if pyopengl 3.x kept the same interface, of returning a string.


cheers,

----------------------------------------------------------------------

>Comment By: Mike C. Fletcher (mcfletch)
Date: 2008-06-13 12:33

Message:
Logged In: YES 
user_id=34901
Originator: NO

Okay, glReadPixels and glGetTexImage now return strings in the default
calls iff you specify GL_UNSIGNED_BYTE format.  There's a test case that
should trigger if that changes in the future.

----------------------------------------------------------------------

Comment By: Mike C. Fletcher (mcfletch)
Date: 2008-06-10 22:46

Message:
Logged In: YES 
user_id=34901
Originator: NO

Okay, I'm swayed.

I was thinking of using the Python string as an input.  If you convert
from another object it should be fine.  I'm okay with the change (can't say
I like it, but compatibility is a pretty high priority).

If you don't get to it I'll try to get it done on Friday before doing a
release.

----------------------------------------------------------------------

Comment By: Rene Dudfield (illume)
Date: 2008-06-06 19:35

Message:
Logged In: YES 
user_id=2042
Originator: NO

Hi,

lots of old versions of pygame are still in use - so this pyopengl API
break is still important to fix for pyopengl+pygame users using old
versions of pygame.

I don't think it should always return a string, but instead default to
returning a string.  This will break less software since this is what 1.x
and 2.x do.  Note pygame using programs are not the only program that
expects a string to be returned.

I don't know what you're talking about with the small string caching
mechanisms breaking things?  Is this a pyopengl3 small string cache?  You
can just convert a ctypes string to a python string with no issues.

I can make the fix if you think it's ok?


Here's a work around screenshot function for gl - that works for all
versions of pyopengl.
The main lines are these:
       data = glReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE)
       if hasattr(data, "tostring"):
           data = data.tostring()

Where it looks to see if the return variable has a tostring() method -
which is what the numpy instance has.



def savescreen(screen, filename):

   def readScreen(x, y, width, height):
       """ Read in the screen information in the area specified """
       glFinish()
       glPixelStorei(GL_PACK_ALIGNMENT, 4)
       glPixelStorei(GL_PACK_ROW_LENGTH, 0)
       glPixelStorei(GL_PACK_SKIP_ROWS, 0)
       glPixelStorei(GL_PACK_SKIP_PIXELS, 0)

       data = glReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE)
       if hasattr(data, "tostring"):
           data = data.tostring()

       return data
   def saveImageData(width, height, data, filename):
       """ Save image data """
       surface = pygame.image.fromstring(data, (width, height), 'RGB', 1)
       pygame.image.save(surface, filename)

   data = readScreen(0,0, screen.get_width(), screen.get_height())
   saveImageData(screen.get_width(), screen.get_height(), data, filename)


----------------------------------------------------------------------

Comment By: Mike C. Fletcher (mcfletch)
Date: 2008-06-06 12:44

Message:
Logged In: YES 
user_id=34901
Originator: NO

Pygame has already changed their code to support PyOpenGL 3.x, the new
version allows the user to specify the data-type they want to have returned
from array-producing code, but at the moment strings are not an option (no
way to generate them in the correct dimensions yet without potentially
falling afoul of the small-string caching mechanisms).

I'm afraid I'll have to mark this "won't fix" as a result.  If you feel
this is a major problem, reopen the ticket and I'll consider it again, but
aside from maybe implementing a "string" output type that could be
selected, I don't see it as a desirable change to make the function always
return strings.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105988&aid=1959860&group_id=5988

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
PyOpenGL Homepage
http://pyopengl.sourceforge.net