Fixes to osg::Image::createImage(..), and addition of code to Viewer.cpp to support

output of screen snapshot via 'O'.
This commit is contained in:
Robert Osfield
2002-04-14 13:41:13 +00:00
parent 03e9f63d54
commit 09d41789da
4 changed files with 48 additions and 30 deletions

View File

@@ -1053,6 +1053,30 @@ void Viewer::keyboard(unsigned char key, int x, int y)
help(osg::notify(osg::NOTICE));
break;
case 'O' :
{
osg::Viewport* viewport = sceneView->getViewport();
if (viewport)
{
std::string filename("screenshot.bmp");
glReadBuffer(GL_FRONT);
osg::ref_ptr<Image> image = osgNew osg::Image;
image->readPixels(viewport->x(),viewport->y(),viewport->width(),viewport->height(),
GL_RGB,GL_UNSIGNED_BYTE);
osgDB::writeImageFile(*image,filename);
osg::notify(osg::NOTICE) << "Saved screen image to `"<<filename<<"`"<< std::endl;
}
else
{
osg::notify(osg::NOTICE) << "Cannot create snapshot of screen, no valid viewport attached"<< std::endl;
}
}
break;
case 'i' :
case 'r' :
{