Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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).
  • Loading branch information...
commit b538836b3d7a09d0165b296a1d3db666a7a498c7 1 parent 8661ec3
Robert OSFIELD authored
View
2  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( "<<vfov<<", "<<width/height<<", "<<0.1<<", "<<1000.0<<");"<<std::endl;
}
class ForwardToDeviceEventHandler : public osgGA::GUIEventHandler {
View
7 examples/osgframerenderer/CaptureSettings.cpp
@@ -157,7 +157,7 @@ REGISTER_OBJECT_WRAPPER( gsc_CaptureSettings,
ADD_ENUM_VALUE( OFF );
ADD_ENUM_VALUE( HORIZONTAL_SPLIT );
ADD_ENUM_VALUE( VERTICAL_SPLIT );
- END_ENUM_SERIALIZER(); // _renderTargetImplementation
+ END_ENUM_SERIALIZER();
ADD_BOOL_SERIALIZER( Offscreen, false );
ADD_BOOL_SERIALIZER( OutputImageFlip, false );
@@ -168,6 +168,11 @@ REGISTER_OBJECT_WRAPPER( gsc_CaptureSettings,
ADD_FLOAT_SERIALIZER( ScreenWidth, 0.0 );
ADD_FLOAT_SERIALIZER( ScreenHeight, 0.0 );
ADD_FLOAT_SERIALIZER( ScreenDistance, 0.0 );
+
+ BEGIN_ENUM_SERIALIZER( PixelFormat, RGB );
+ ADD_ENUM_VALUE( RGB );
+ ADD_ENUM_VALUE( RGBA );
+ END_ENUM_SERIALIZER();
ADD_UINT_SERIALIZER( Samples, 0 );
ADD_UINT_SERIALIZER( SampleBuffers, 0 );
View
11 examples/osgframerenderer/CaptureSettings.h
@@ -60,6 +60,16 @@ class CaptureSettings : public osg::Object
void setScreenDistance(float distance) { _screenDistance = distance; }
float getScreenDistance() const { return _screenDistance; }
+
+ enum PixelFormat
+ {
+ RGB,
+ RGBA
+ };
+
+ void setPixelFormat(PixelFormat format) { _pixelFormat = format; }
+ PixelFormat getPixelFormat() const { return _pixelFormat; }
+
void setSamples(unsigned int s) { _samples = s; }
unsigned int getSamples() const { return _samples; }
@@ -121,6 +131,7 @@ class CaptureSettings : public osg::Object
float _screenHeight;
float _screenDistance;
+ PixelFormat _pixelFormat;
unsigned int _samples;
unsigned int _sampleBuffers;
View
26 examples/osgframerenderer/osgframerenderer.cpp
@@ -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;
View
18 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;
View
2  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;

0 comments on commit b538836

Please sign in to comment.
Something went wrong with that request. Please try again.