Hi Mathias,

I've used the following python snippet to make hi-res screenshots
using a slave camera and an FBO. I'm sure you could (or should) do
this with a draw callback, but I started with explicitly calling this
function myself to do some experimentation first. I did have some
trouble on one machine, where the context (and so the image) would
only contain the clear color. You could fill a numpy array from the
image I guess. I would be interested in that.

regards,
Gerwin

---

def fboshot(pFileName="screenshot.png", pWidth=1024,pHeight=768):
    """
    screenshot experiment with a frame buffer object
    creates a new slave camera, attached to the viewer, draws, saves
to image, removes the camera again
    """
    import osg
    import osgDB

    viewer= __main__.viewer
    cam = viewer.getCamera()

    #prepare an image, to which a camera can render
    shot = osg.Image()
    shot.allocateImage(pWidth,pHeight,1, osg.GL_RGB, osg.GL_UNSIGNED_BYTE)

    #create a camera with an fbo render target
    hicam = osg.Camera()
    hicam.setGraphicsContext(cam.getGraphicsContext())
    hicam.setRenderTargetImplementation(osg.Camera.FRAME_BUFFER_OBJECT)
    hicam.attach(osg.Camera.COLOR_BUFFER,shot)
    hicam.setViewport(0,0,pWidth,pHeight)

    #add a slave camera
    viewer.addSlave(hicam)

    #render one frame
    viewer.frame()

    #store the shot taken
    osgDB.writeImageFile(shot,pFileName)

    #remove this camera again
    viewer.removeSlave(0)

On Fri, Feb 20, 2009 at 4:54 PM, Mathias Franzius
<[email protected]> wrote:
> Dear ng,
>
> first of all thanks for the support for my last questions!
>
> I try to get a scene snapshot into a numpy array.
> In pure OpenGL I used a QT or glut context and glReadPixels and converted 
> that to a numpy array using scipy.
> My problem on osg is that the context seems to be deactivated after a 
> viewer.frame() call - glReadPixels returns only zeros.
> So I guess either I need to keep the context active, reactivate it, or 
> register a callback somehow in a post render phase (?).
> Furthermore, if I want to use the osg method with a camera-attached 
> osg.Image, I'll need to convert the Image.data() to numpy format.
> Has sb got an idea (or even a code snippet) that would work in osgswig?
>
> Thanks a lot!
>   Mathias
> _______________________________________________________________________
> Jetzt 1 Monat kostenlos! WEB.DE FreeDSL - Telefonanschluss + DSL
> für nur 17,95 EURO/mtl.!* http://dsl.web.de/?ac=OM.AD.AD008K15039B7069a
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to