I'm using PostDrawCallback to make a screenshot in a realtime environment
with CompositeViewer. Therefor I add this callback when user wants to make
the screenshot. But after adding this callback to the camera, a screenshot
is taken after each new frame. I just want to have a screenshot of the
current frame and then the callback should be automatically removed. I can't
find a method to remove the callback from the camera after successfully
taking a screenshot.
Who knows how to solve this problem?
The code follows:
class ScreenShotCallback: public osg::Camera::DrawCallback {
private:
double _w,_h;
char* _filename;
public:
ScreenShotCallback(double w,double h,char* f)
{
_w = w;
_h = h;
_filename = f;
}
~ScreenShotCallback() {};
void operator() (const osg::Camera &camera) const {
osg::ref_ptr<osg::Image> frame = new osg::Image;
frame->readPixels(0, 0, _w, _h, GL_RGB, GL_UNSIGNED_BYTE);
osgDB::writeImageFile(*frame, _filename);
}
}
};
in the main:
viewer->getView(viewer->getNumViews()-1)->getCamera()->setPostDrawCallback(new
ScreenShotCallback(_twidth,_theight,filename));
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org