|
按照http://bbs.vrchina.net/redirect.php?tid=3396&goto=lastpost这里编写的,但是不知道为什么根本没有文件生成,哪边出问题了?那位帮忙看看呀。
#include <osgViewer/Viewer>
#include <osg/Camera>
#include <osg/Image>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
class PostDrawCallback:public osg::Camera:rawCallback
{
public:
PostDrawCallback():
virtual void operator()(const osg::Camera &camera)
{
osg::ref_ptr<osg::Image>image = new osg::Image;
unsigned int w=1600,h=900;
image->allocateImage( w, h, 1, GL_RGB, GL_UNSIGNED_BYTE);
image->readPixels( 0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE);
osgDB::writeImageFile( *(image.get()), "cc.bmp" );
}
};
class ImageHandler:public osgGA::GUIEventHandler
{
public:
ImageHandler(){};
~ImageHandler(){};
bool handle( const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa )
{
osgViewer::Viewer* viewer =
dynamic_cast<osgViewer::Viewer*>(&aa);
if (!viewer)
return false;
switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::KEYDOWN):
{
if(ea.getKey() == 'c')
{
viewer->getCamera()->setPostDrawCallback(new PostDrawCallback);
}
}
default:
return false;
}
}
};
int main( int, char ** )
{
osgViewer::Viewer viewer;
viewer.setSceneData( osgDB::readNodeFile( "cow.osg" ) );
if (!viewer.getSceneData())
{
osg::notify( osg::FATAL ) << "Unable to load data file. Exiting." << std::endl;
return 1;
}
viewer.addEventHandler( new ImageHandler );
return viewer.run();
} |
|