|
本帖最后由 TwinkleStarlet 于 2015-12-23 11:43 编辑
#include <osg/Camera>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgGA/TrackballManipulator>
#include <osg/Image>
bool snap(osg::ref_ptr<osgViewer::Viewer> v)
{
int width = v->getCamera()->getViewport()->width();
int height=v->getCamera()->getViewport()->height();
double left,right,bottom,top,zNear,zFar;
v->getCamera()->getProjectionMatrixAsFrustum(left,right,bottom,top,zNear,zFar);
printf("left=%.2f\tright=%.2f\nbottom=%.2f\ttop=%.2f",left,right,bottom,top);
v->getCamera()->setProjectionMatrixAsFrustum(left,right,bottom,top,zNear,zFar);
v->renderingTraversals();
osg::ref_ptr<osg::Image> image=new osg::Image;
image->readPixels(0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE);
osgDB::writeImageFile(*image,"d:\\pic.bmp");
return true;
}
int main()
{
osg::ref_ptr<osgViewer::Viewer>v=new osgViewer::Viewer;
v->setSceneData(osgDB::readNodeFile("cow.osg"));
v->setCameraManipulator(new osgGA::TrackballManipulator());
v->frame();
snap(v);
return 1;
}
渲染效果没错,但是抓图 的效果如下,是白屏,有大侠知道吗?
|
|