Added support for RGBA colour buffer in osgframerenderer using the --rgba command line option (--rgb selects the standard non colour frame buffer which is the default).
This commit is contained in:
@@ -17,7 +17,8 @@
|
||||
|
||||
struct ScreenShot : public osg::Camera::DrawCallback
|
||||
{
|
||||
ScreenShot(bool flip):
|
||||
ScreenShot(GLenum pixelFormat, bool flip):
|
||||
_pixelFormat(pixelFormat),
|
||||
_flip(flip) {}
|
||||
|
||||
virtual void operator () (osg::RenderInfo& renderInfo) const
|
||||
@@ -41,13 +42,13 @@ struct ScreenShot : public osg::Camera::DrawCallback
|
||||
osg::Viewport* viewport = camera ? camera->getViewport() : 0;
|
||||
if (viewport)
|
||||
{
|
||||
OSG_NOTICE<<"Doing read of ="<<viewport->x()<<", "<<viewport->y()<<", "<<viewport->width()<<", "<<viewport->height()<<std::endl;
|
||||
OSG_NOTICE<<"Doing read of ="<<viewport->x()<<", "<<viewport->y()<<", "<<viewport->width()<<", "<<viewport->height()<<" with pixelFormat=0x"<<std::hex<<_pixelFormat<<std::dec<<std::endl;
|
||||
|
||||
glReadBuffer(camera->getDrawBuffer());
|
||||
osg::ref_ptr<osg::Image> image = new osg::Image;
|
||||
|
||||
image->readPixels(viewport->x(),viewport->y(),viewport->width(),viewport->height(),
|
||||
GL_RGB, GL_UNSIGNED_BYTE, 1);
|
||||
_pixelFormat, GL_UNSIGNED_BYTE, 1);
|
||||
|
||||
if (_flip) image->flipVertical();
|
||||
|
||||
@@ -58,6 +59,7 @@ struct ScreenShot : public osg::Camera::DrawCallback
|
||||
|
||||
typedef std::map<const osg::Camera*, unsigned int> CameraNumMap;
|
||||
|
||||
GLenum _pixelFormat;
|
||||
bool _flip;
|
||||
osg::ref_ptr<gsc::CaptureSettings> _frameCapture;
|
||||
CameraNumMap _cameraNumMap;
|
||||
@@ -239,8 +241,13 @@ int main( int argc, char **argv )
|
||||
unsigned int height = 512;
|
||||
if (arguments.read("--height",height)) fc->setHeight(height);
|
||||
|
||||
if (arguments.read("--rgb")) fc->setPixelFormat(gsc::CaptureSettings::RGB);
|
||||
if (arguments.read("--rgba")) fc->setPixelFormat(gsc::CaptureSettings::RGBA);
|
||||
|
||||
|
||||
osg::Vec4 clearColor(0.0f,0.0f,0.0f,0.0f);
|
||||
while (arguments.read("--clear-color",clearColor[0],clearColor[1],clearColor[2],clearColor[3])) {}
|
||||
|
||||
|
||||
unsigned int samples = 0;
|
||||
if (arguments.read("--samples",samples)) fc->setSamples(samples);
|
||||
|
||||
@@ -380,6 +387,7 @@ int main( int argc, char **argv )
|
||||
traits->y = 0;
|
||||
traits->width = fc->getWidth();
|
||||
traits->height = fc->getHeight();
|
||||
traits->alpha = (fc->getPixelFormat() == gsc::CaptureSettings::RGBA) ? 8 : 0;
|
||||
traits->samples = fc->getSamples();
|
||||
traits->sampleBuffers = fc->getSampleBuffers();
|
||||
traits->windowDecoration = !(fc->getOffscreen());
|
||||
@@ -394,7 +402,7 @@ int main( int argc, char **argv )
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
viewer.getCamera()->setClearColor(clearColor);
|
||||
viewer.getCamera()->setGraphicsContext(gc.get());
|
||||
viewer.getCamera()->setDisplaySettings(ds.get());
|
||||
|
||||
@@ -417,6 +425,10 @@ int main( int argc, char **argv )
|
||||
// double hfov = osg::RadiansToDegrees(atan2(width/2.0f,distance)*2.0);
|
||||
|
||||
viewer.getCamera()->setProjectionMatrixAsPerspective( vfov*fovy_multiple, (screenWidth/screenHeight)*fovx_multiple, 0.1, 1000.0);
|
||||
|
||||
OSG_NOTICE<<"setProjectionMatrixAsPerspective( "<<vfov*fovy_multiple<<", "<<(screenWidth/screenHeight)*fovx_multiple<<", "<<0.1<<", "<<1000.0<<");"<<std::endl;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -466,13 +478,15 @@ int main( int argc, char **argv )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GLenum pixelFormat = (fc->getPixelFormat()==gsc::CaptureSettings::RGBA) ? GL_RGBA : GL_RGB;
|
||||
|
||||
|
||||
viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
|
||||
viewer.realize();
|
||||
|
||||
// set up screen shot
|
||||
osg::ref_ptr<ScreenShot> screenShot = new ScreenShot(fc->getOutputImageFlip());;
|
||||
osg::ref_ptr<ScreenShot> screenShot = new ScreenShot(pixelFormat, fc->getOutputImageFlip());;
|
||||
{
|
||||
|
||||
osgViewer::Viewer::Cameras cameras;
|
||||
|
||||
Reference in New Issue
Block a user