From c15d07caa182d2198b659b07d384b22774a6e729 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 17 Dec 2012 15:58:57 +0000 Subject: [PATCH] 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). --- applications/present3D/present3D.cpp | 2 ++ examples/osgframerenderer/CaptureSettings.cpp | 7 ++++- examples/osgframerenderer/CaptureSettings.h | 11 ++++++++ .../osgframerenderer/osgframerenderer.cpp | 26 ++++++++++++++----- src/osgPlugins/p3d/ReaderWriterP3D.cpp | 18 ++++++------- src/osgPresentation/SlideShowConstructor.cpp | 2 +- 6 files changed, 49 insertions(+), 17 deletions(-) diff --git a/applications/present3D/present3D.cpp b/applications/present3D/present3D.cpp index 838a3731d..3d53439a1 100644 --- a/applications/present3D/present3D.cpp +++ b/applications/present3D/present3D.cpp @@ -128,6 +128,8 @@ void setViewer(osgViewer::Viewer& viewer, float width, float height, float dista // double hfov = osg::RadiansToDegrees(atan2(width/2.0f,distance)*2.0); viewer.getCamera()->setProjectionMatrixAsPerspective( vfov, width/height, 0.1, 1000.0); + + OSG_NOTICE<<"setProjectionMatrixAsPerspective( "<getViewport() : 0; if (viewport) { - OSG_NOTICE<<"Doing read of ="<x()<<", "<y()<<", "<width()<<", "<height()<y()<<", "<width()<<", "<height()<<" with pixelFormat=0x"<getDrawBuffer()); osg::ref_ptr 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 CameraNumMap; + GLenum _pixelFormat; bool _flip; osg::ref_ptr _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( "<getPixelFormat()==gsc::CaptureSettings::RGBA) ? GL_RGBA : GL_RGB; viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); viewer.realize(); // set up screen shot - osg::ref_ptr screenShot = new ScreenShot(fc->getOutputImageFlip());; + osg::ref_ptr screenShot = new ScreenShot(pixelFormat, fc->getOutputImageFlip());; { osgViewer::Viewer::Cameras cameras; diff --git a/src/osgPlugins/p3d/ReaderWriterP3D.cpp b/src/osgPlugins/p3d/ReaderWriterP3D.cpp index ff1755512..ae9b4ef2e 100644 --- a/src/osgPlugins/p3d/ReaderWriterP3D.cpp +++ b/src/osgPlugins/p3d/ReaderWriterP3D.cpp @@ -41,15 +41,15 @@ class ReaderWriterP3DXML : public osgDB::ReaderWriter public: ReaderWriterP3DXML() { - _colorMap["WHITE"] .set(1.0f,1.0f,1.0f,1.0f); - _colorMap["BLACK"] .set(0.0f,0.0f,0.0f,1.0f); - _colorMap["PURPLE"] .set(1.0f,0.0f,1.0f,1.0f); - _colorMap["BLUE"] .set(0.0f,0.0f,1.0f,1.0f); - _colorMap["RED"] .set(1.0f,0.0f,0.0f,1.0f); - _colorMap["CYAN"] .set(0.0f,1.0f,1.0f,1.0f); - _colorMap["YELLOW"] .set(1.0f,1.0f,0.0f,1.0f); - _colorMap["GREEN"] .set(0.0f,1.0f,0.0f,1.0f); - _colorMap["SKY"] .set(0.2f, 0.2f, 0.4f, 1.0f); + _colorMap["WHITE"] .set(1.0f,1.0f,1.0f,0.0f); + _colorMap["BLACK"] .set(0.0f,0.0f,0.0f,0.0f); + _colorMap["PURPLE"] .set(1.0f,0.0f,1.0f,0.0f); + _colorMap["BLUE"] .set(0.0f,0.0f,1.0f,0.0f); + _colorMap["RED"] .set(1.0f,0.0f,0.0f,0.0f); + _colorMap["CYAN"] .set(0.0f,1.0f,1.0f,0.0f); + _colorMap["YELLOW"] .set(1.0f,1.0f,0.0f,0.0f); + _colorMap["GREEN"] .set(0.0f,1.0f,0.0f,0.0f); + _colorMap["SKY"] .set(0.2f, 0.2f, 0.4f, 0.0f); _layoutMap["LEFT_TO_RIGHT"] = osgText::Text::LEFT_TO_RIGHT; _layoutMap["RIGHT_TO_LEFT"] = osgText::Text::RIGHT_TO_LEFT; diff --git a/src/osgPresentation/SlideShowConstructor.cpp b/src/osgPresentation/SlideShowConstructor.cpp index beaf4762e..3c2c8e1e7 100644 --- a/src/osgPresentation/SlideShowConstructor.cpp +++ b/src/osgPresentation/SlideShowConstructor.cpp @@ -168,7 +168,7 @@ SlideShowConstructor::SlideShowConstructor(osgDB::Options* options): _hudSettings = new HUDSettings(_slideDistance, ds->getEyeSeparation()*0.5, _leftEyeMask, _rightEyeMask); - _backgroundColor.set(0.0f,0.0f,0.0f,1.0f); + _backgroundColor.set(0.0f,0.0f,0.0f,0.0f); _presentationDuration = -1.0;