Hi,

I was wondering what the best approach to capturing an image that has been 
rendered to texture is?  In my application, I'm needing to capture frames to 
file and/or memory buffers at various intervals.  In my camera node that I 
have set up, the texture that is associated has a NULL osg::Image (using 
getImage()); and I believe that is the case for all RTT examples that I have 
looked at.

I imagine that I could simply bind the texture and call glReadPixels, 
however it seems to me that doing this might not give the results that I'm 
wanting which is the actual texture's image.  I don't want to do a screen 
capture, per se, which is what I think that using glReadPixels would 
ultimately accomplish.  Capturing the output of the texture to a buffer is 
what I need.  I am hoping there is a way to do this that is already built 
into OSG.

My first stab at this was to get the TextureObjectList to obtain the texture 
ID, bind that texture ID, and then call glReadPixels.  I've tried the 
following code, but nothing is ever copied to the data buffer.  Of course, 
my OpenGL knowledge is a bit limited in this area, so I have no idea as to 
the correctness of this approach.  Any help would be greatly appreciated.

        osg::Image *image = tex->getImage();
        unsigned char *data = new unsigned char[512 * 512 *4];

        osg::Texture::TextureObjectListMap map;

        tex->takeTextureObjects(map);
        osg::Texture::TextureObjectList& tol = map[0];

        // reset the time of any uninitialized objects.
        osg::Texture::TextureObjectList::iterator iter;
        iter = tol.begin();

        osg::Texture::TextureObject* obj = (*iter).get();

        if (data && obj)
        {
            glBindTexture(GL_TEXTURE_2D, obj->_id);
            glReadPixels(0, 0, obj->_width, obj->_height, GL_RGBA, 
GL_UNSIGNED_BYTE, data);
            glBindTexture(GL_TEXTURE_2D, 0);
        }


Thanks,
Brian




_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to