From 09d41789da6e69839fe54195f9f391e32ef43ba7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 14 Apr 2002 13:41:13 +0000 Subject: [PATCH] Fixes to osg::Image::createImage(..), and addition of code to Viewer.cpp to support output of screen snapshot via 'O'. --- include/osg/Image | 2 -- src/osg/Image.cpp | 28 +++++++++++--------------- src/osgGLUT/Viewer.cpp | 24 ++++++++++++++++++++++ src/osgPlugins/bmp/ReaderWriterBMP.cpp | 24 +++++++++++----------- 4 files changed, 48 insertions(+), 30 deletions(-) diff --git a/include/osg/Image b/include/osg/Image index 87320d400..0e25c536f 100644 --- a/include/osg/Image +++ b/include/osg/Image @@ -137,8 +137,6 @@ class SG_EXPORT Image : public Object Image& operator = (const Image&) { return *this; } - void computePixelSize(); - std::string _fileName; int _s, _t, _r; GLint _internalTextureFormat; diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index 294e78b44..1ad4ff957 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -63,11 +63,6 @@ void Image::setFileName(const std::string& fileName) _fileName = fileName; } - -void Image::computePixelSize() -{ -} - #ifndef GL_VERSION_1_2 /* 1.2 definitions...*/ #define GL_BGR 0x80E0 @@ -130,19 +125,19 @@ const unsigned int Image::computeNumComponents(GLenum type) const unsigned int Image::computePixelSizeInBits(GLenum format,GLenum type) { - switch(format) + switch(type) { - case(GL_BITMAP): return computeNumComponents(type); + case(GL_BITMAP): return computeNumComponents(format); case(GL_BYTE): - case(GL_UNSIGNED_BYTE): return 8*computeNumComponents(type); + case(GL_UNSIGNED_BYTE): return 8*computeNumComponents(format); case(GL_SHORT): - case(GL_UNSIGNED_SHORT): return 16*computeNumComponents(type); + case(GL_UNSIGNED_SHORT): return 16*computeNumComponents(format); case(GL_INT): case(GL_UNSIGNED_INT): - case(GL_FLOAT): return 32*computeNumComponents(type); + case(GL_FLOAT): return 32*computeNumComponents(format); case(GL_UNSIGNED_BYTE_3_3_2): @@ -159,7 +154,7 @@ const unsigned int Image::computePixelSizeInBits(GLenum format,GLenum type) case(GL_UNSIGNED_INT_8_8_8_8_REV): case(GL_UNSIGNED_INT_10_10_10_2): case(GL_UNSIGNED_INT_2_10_10_10_REV): return 32; - default: return false; + default: return 0; } } @@ -169,7 +164,7 @@ const unsigned int Image::computeRowWidthInBytes(int width,GLenum format,GLenum unsigned int pixelSize = computePixelSizeInBits(format,type); int widthInBits = width*pixelSize; int packingInBits = packing*8; - return (widthInBits/packingInBits + (widthInBits%packingInBits)?1:0)*packing; + return (widthInBits/packingInBits + ((widthInBits%packingInBits)?1:0))*packing; } @@ -185,7 +180,10 @@ void Image::createImage(int s,int t,int r, { if (_data) ::free(_data); - _data = (unsigned char *)malloc (newTotalSize); + if (newTotalSize) + _data = (unsigned char *)malloc (newTotalSize); + else + _data = 0L; } if (_data) @@ -231,8 +229,6 @@ void Image::setImage(int s,int t,int r, _data = data; _packing = packing; - computePixelSize(); - // test scaling... // scaleImageTo(16,16,_r); @@ -270,7 +266,7 @@ void Image::scaleImage(const int s,const int t,const int r) // need to sort out what size to really use... unsigned char* newData = (unsigned char *)malloc(newTotalSize); - if (newData) + if (!newData) { // should we throw an exception??? Just return for time being. notify(FATAL) << "Error Image::scaleImage() do not succeed : out of memory."<getViewport(); + if (viewport) + { + + std::string filename("screenshot.bmp"); + + glReadBuffer(GL_FRONT); + osg::ref_ptr 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 `"<