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:
parent
f7bee82e99
commit
c15d07caa1
@ -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 {
|
||||
|
@ -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 );
|
||||
@ -169,6 +169,11 @@ REGISTER_OBJECT_WRAPPER( gsc_CaptureSettings,
|
||||
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 );
|
||||
|
||||
|
@ -60,6 +60,16 @@ public:
|
||||
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 @@ protected:
|
||||
float _screenHeight;
|
||||
float _screenDistance;
|
||||
|
||||
PixelFormat _pixelFormat;
|
||||
unsigned int _samples;
|
||||
unsigned int _sampleBuffers;
|
||||
|
||||
|
@ -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,6 +241,11 @@ 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;
|
||||
@ -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
|
||||
{
|
||||
@ -467,12 +479,14 @@ int main( int argc, char **argv )
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user