| | 32 | class WindowCaptureCallback : public osg::Camera::DrawCallback |
| | 33 | { |
| | 34 | public: |
| | 35 | |
| | 36 | WindowCaptureCallback() |
| | 37 | { |
| | 38 | } |
| | 39 | |
| | 40 | virtual void operator () (osg::RenderInfo& renderInfo) const |
| | 41 | { |
| | 42 | osg::GraphicsContext* gc = renderInfo.getState()->getGraphicsContext(); |
| | 43 | osg::notify(osg::NOTICE)<<"Capture screen image "<<gc<<std::endl; |
| | 44 | |
| | 45 | } |
| | 46 | }; |
| | 47 | |
| | 48 | void addCallbackToViewer(osgViewer::ViewerBase& viewer, WindowCaptureCallback* callback) |
| | 49 | { |
| | 50 | osgViewer::ViewerBase::Windows windows; |
| | 51 | viewer.getWindows(windows); |
| | 52 | for(osgViewer::ViewerBase::Windows::iterator itr = windows.begin(); |
| | 53 | itr != windows.end(); |
| | 54 | ++itr) |
| | 55 | { |
| | 56 | osgViewer::GraphicsWindow* window = *itr; |
| | 57 | osg::GraphicsContext::Cameras& cameras = window->getCameras(); |
| | 58 | osg::Camera* lastCamera = 0; |
| | 59 | for(osg::GraphicsContext::Cameras::iterator cam_itr = cameras.begin(); |
| | 60 | cam_itr != cameras.end(); |
| | 61 | ++cam_itr) |
| | 62 | { |
| | 63 | if (lastCamera) |
| | 64 | { |
| | 65 | if ((*cam_itr)->getRenderOrder() > (*cam_itr)->getRenderOrder()) |
| | 66 | { |
| | 67 | lastCamera = (*cam_itr); |
| | 68 | } |
| | 69 | if ((*cam_itr)->getRenderOrder() == lastCamera->getRenderOrder() && |
| | 70 | (*cam_itr)->getRenderOrderNum() >= lastCamera->getRenderOrderNum()) |
| | 71 | { |
| | 72 | lastCamera = (*cam_itr); |
| | 73 | } |
| | 74 | } |
| | 75 | else |
| | 76 | { |
| | 77 | lastCamera = *cam_itr; |
| | 78 | } |
| | 79 | } |
| | 80 | |
| | 81 | if (lastCamera) |
| | 82 | { |
| | 83 | osg::notify(osg::NOTICE)<<"Last camera "<<lastCamera<<std::endl; |
| | 84 | |
| | 85 | lastCamera->setFinalDrawCallback(callback); |
| | 86 | } |
| | 87 | else |
| | 88 | { |
| | 89 | osg::notify(osg::NOTICE)<<"No camera found"<<std::endl; |
| | 90 | } |
| | 91 | } |
| | 92 | } |
| | 93 | |