|
楼主 |
发表于 2011-12-7 16:35:01
|
显示全部楼层
本帖最后由 luo9168 于 2011-12-7 17:16 编辑
下面是查找的一些资料:
查到了这个帖子。
osghud例子中的SnapImage类的写法为:- struct SnapImage : public osg::Camera::DrawCallback
- {
- SnapImage(const std::string& filename):
- _filename(filename),
- _snapImage(false)
- {
- _image = new osg::Image;
- }
- virtual void operator () (osg::RenderInfo& renderInfo) const
- {
- if (!_snapImage) return;
-
- osg::notify(osg::NOTICE)<<"Camera callback"<<std::endl;
- osg::Camera* camera = renderInfo.getCurrentCamera();
- osg::Viewport* viewport = camera ? camera->getViewport() : 0;
- osg::notify(osg::NOTICE)<<"Camera callback "<<camera<<" "<<viewport<<std::endl;
- if (viewport && _image.valid())
- {
- _image->readPixels(int(viewport->x()),int(viewport->y()),int(viewport->width()),int(viewport->height()),
- GL_RGBA,
- GL_UNSIGNED_BYTE);
- osgDB::writeImageFile(*_image, _filename);
-
- osg::notify(osg::NOTICE)<<"Taken screenshot, and written to '"<<_filename<<"'"<<std::endl;
- }
-
- _snapImage = false;
- }
- std::string _filename;
- mutable bool _snapImage;
- mutable osg::ref_ptr<osg::Image> _image;
- };
复制代码 其中osg::Image::readPixels的解释如下:
virtual void osg::Image::readPixels ( int x, int y, int width, int height, GLenum pixelFormat, GLenum type );
Read pixels from current frame buffer at specified position and size, using glReadPixels.
Create memory for storage if required, reuse existing pixel coords if possible. |
|