Hi!

I have a cameraNode and i need to take a screenshot. I see that the producer camera implements a postDrawcallback to take the screenshot. I copy this code for my cameranode (yes, i have a osg::CameraNode camera) and it doesn't works. I debug it and never calls the operator(). Someone can i help me???

this is my drawcallback class...

class SnapImageDrawCallback : public osg::CameraNode::DrawCallback
{
public:

        SnapImageDrawCallback():
        _snapImageOnNextFrame(false)
        {
        }

        void setFileName(const std::string& filename) { _filename = filename; }
                        const std::string& getFileName() const { return 
_filename; }

        void setSnapImageOnNextFrame(bool flag) { _snapImageOnNextFrame = flag; 
}
        bool getSnapImageOnNextFrame() const { return _snapImageOnNextFrame; }

        virtual void operator () (const osg::CameraNode& camera) const
        {
                if (!_snapImageOnNextFrame) return;

                int x,y,width,height;
                camera.getViewport()->getViewport(x,y,width,height);

                osg::ref_ptr<osg::Image> image = new osg::Image;
                image->readPixels(x,y,width,height,GL_RGB,GL_UNSIGNED_BYTE);

                if (osgDB::writeImageFile(*image,_filename))
                {
osg::notify(osg::NOTICE) << "Saved screen image to `"<<_filename<<"`"<< std::endl;
                }

                _snapImageOnNextFrame = false;
        }

        protected:

                std::string _filename;
                bool        _snapImageOnNextFrame;

};

and then asign the callback to my cameranode:

SnapImageDrawCallback* snapImageDrawCallback = new SnapImageDrawCallback();
sceneView->getCamera()->setPostDrawCallback(snapImageDrawCallback);



----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to