Hi,
I'm assuming you're using OpenGL/PyGame. Creating a surface each time is
going to be slow, because you're converting data from one graphics API to
another, but here's the best way I have:
def GetSurface(rect=False):
if not rect:
size = glGetFloatv(GL_VIEWPORT)
size = [int(round(size[2])),int(round(size[3]))]
rect = [0,0,size[0],size[1]]
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(rect[0],rect[1],rect[2],rect[3],GL_RGB,GL_UNSIGNED_BYTE)
return pygame.image.fromstring(data,(rect[2],rect[3]),'RGB',1)
This works quickly enough for real-time capture, but it's certainly not
speedy--and will ding your framerate significantly, especially if lots of
other stuff is being done as well...
The best approach is almost certainly to do it differently. What is the
overall problem you're trying to solve?
Ian