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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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)
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.
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.
Logged In: YES
user_id=34901
Originator: NO
Forgot to close.