[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Depth Screenshot



I would suggest PIL - don't have the exact functions for it off the top of my head though...

On Tue, Oct 6, 2009 at 9:43 PM, Ian Mallett <geometrian@xxxxxxxxx> wrote:
Hello,

I'm trying to debug a weird FBO/depth problem, and it would be great to have screenshots of the depth.  My current method does not work:

def ScreenSurf(rect=AUTO,type=RGB,framebuffer=0):
    if rect == AUTO:
        size = glGetFloatv(GL_VIEWPORT)
        size = [int(round(size[2])),int(round(size[3]))]
        rect = [0,0,size[0],size[1]]
    glPixelStorei(GL_PACK_ROW_LENGTH,0)
    glPixelStorei(GL_PACK_SKIP_ROWS,0)
    glPixelStorei(GL_PACK_SKIP_PIXELS,0)
    if type==RGBA:
        glPixelStorei(GL_PACK_ALIGNMENT,4)
    elif type==RGB:
        glPixelStorei(GL_PACK_ALIGNMENT,1)
    elif type==DEPTH:
        glPixelStorei(GL_PACK_ALIGNMENT,2)
    try:
        data = "">
        print len(data)
    except:
        previous = glGetIntegerv(GL_READ_BUFFER)
        glReadBuffer(GL_COLOR_ATTACHMENT0_EXT+framebuffer)
        data = "">
        glReadBuffer(previous)
    if type==RGBA:
        return pygame.image.fromstring(data,(rect[2],rect[3]),'RGBA',1)
    elif type==RGB:
        return pygame.image.fromstring(data,(rect[2],rect[3]),'RGB',1)
    elif type==DEPTH:
        #What goes here?


The surface that is returned is then saved (pygame.image.save()). 

The issue is that in the case of depth, data is of length x*y.  In the case of RGB color, it is 3*rect[2]*rect[3].  In the case of RGBA, it is 4*rect[2]*rect[3].  PyGame doesn't know how to convert it (there's no pygame.image.fromstring(data,size,'R',1), for instance).  What's a decent way to save the depth as an image? 

Thanks,
Ian