Hi,
In my application I want to save the current scene as an image every time the
user presses 's'.
I have the basic framework to detect the keypress and it works fine. I am
facing issues in saving the scene.
I wrote the following callback -
Code:
class SnapshotCallback : public Camera::DrawCallback
{
public:
SnapshotCallback()
{
}
void
operator() (osg::RenderInfo &renderInfo) const
{
int width;
int height;
Camera * camera = renderInfo.getCurrentCamera();
width = camera -> getViewport() -> width();
height = camera -> getViewport() -> height();
cerr << "W : " <<width<< "H : "<< height;
osg::ref_ptr< ::osg::Image> image = new ::osg::Image();
image->readPixels(0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE);
if (osgDB::writeImageFile(*image, "./saved_image.bmp"))
{
std::cout << "Saved screen image to '" << std::endl;
}
else
{
cerr << "Could not save image!";
}
}
};
Now in my osgGA::GUIEventHandler derived class i execute the following function
every time the user presses 's' ->
Code:
void
snapshot( const osgGA::GUIEventAdapter& ea
, osgGA::GUIActionAdapter& aa
)
{
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
viewer -> getCamera() -> setFinalDrawCallback(new SnapshotCallback());
viewer -> renderingTraversals();
viewer -> getCamera() -> setFinalDrawCallback(NULL);
}
But the callback doesn't get executed.
I have 2 questions -
1) what am I doing wrong
2) Is this the preferred way to get the snapshot of the scene
Thank you!
Cheers,
Aviral Goel
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=58398#58398
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org