diff --git a/applications/osgviewer/osgviewer.cpp b/applications/osgviewer/osgviewer.cpp index 1c25ad1cc..6a0034c91 100644 --- a/applications/osgviewer/osgviewer.cpp +++ b/applications/osgviewer/osgviewer.cpp @@ -118,12 +118,6 @@ int main(int argc, char** argv) // add the record camera path handler viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); - unsigned int screenNum; - while (arguments.read("--screen",screenNum)) - { - viewer.setUpViewOnSingleScreen(screenNum); - } - // load the data osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); if (!loadedModel) diff --git a/include/osgViewer/View b/include/osgViewer/View index 1fed20395..c869164f6 100644 --- a/include/osgViewer/View +++ b/include/osgViewer/View @@ -148,6 +148,9 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /** Convinience method for creating slave Cameras and associated GraphicsWindows across all screens.*/ void setUpViewAcrossAllScreens(); + /** Convinience method for a single Camara on a single window.*/ + void setUpViewInWindow(int x, int y, int width, int height, unsigned int screenNum=0); + /** Convinience method for a single Camara associated with a single full screen GraphicsWindow.*/ void setUpViewOnSingleScreen(unsigned int screenNum=0); diff --git a/src/osgViewer/View.cpp b/src/osgViewer/View.cpp index c5af967b6..e7535284e 100644 --- a/src/osgViewer/View.cpp +++ b/src/osgViewer/View.cpp @@ -272,7 +272,8 @@ void View::setUpViewAcrossAllScreens() traits->sharedContext = 0; traits->sampleBuffers = ds->getMultiSamples(); traits->samples = ds->getNumMultiSamples(); - if (ds->getStereo() && (ds->getStereoMode() == osg::DisplaySettings::QUAD_BUFFER)) { + if (ds->getStereo() && (ds->getStereoMode() == osg::DisplaySettings::QUAD_BUFFER)) + { traits->quadBufferStereo = true; } osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); @@ -392,6 +393,61 @@ void View::setUpViewAcrossAllScreens() assignSceneDataToCameras(); } +void View::setUpViewInWindow(int x, int y, int width, int height, unsigned int screenNum) +{ + osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance(); + + osg::ref_ptr traits = new osg::GraphicsContext::Traits; + traits->screenNum = screenNum; + traits->x = x; + traits->y = y; + traits->width = width; + traits->height = height; + traits->alpha = ds->getMinimumNumAlphaBits(); + traits->stencil = ds->getMinimumNumStencilBits(); + traits->windowDecoration = true; + traits->doubleBuffer = true; + traits->sharedContext = 0; + traits->sampleBuffers = ds->getMultiSamples(); + traits->samples = ds->getNumMultiSamples(); + if (ds->getStereo() && (ds->getStereoMode() == osg::DisplaySettings::QUAD_BUFFER)) + { + traits->quadBufferStereo = true; + } + + osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); + + _camera->setGraphicsContext(gc.get()); + + osgViewer::GraphicsWindow* gw = dynamic_cast(gc.get()); + if (gw) + { + osg::notify(osg::INFO)<<"View::setUpViewOnSingleScreen - GraphicsWindow has been created successfully."<getEventQueue()->getCurrentEventState()->setWindowRectangle(x, y, width, height ); + } + else + { + osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); + + double newAspectRatio = double(traits->width) / double(traits->height); + double aspectRatioChange = newAspectRatio / aspectRatio; + if (aspectRatioChange != 1.0) + { + _camera->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0); + } + + _camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height)); + + GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; + + _camera->setDrawBuffer(buffer); + _camera->setReadBuffer(buffer); +} + void View::setUpViewOnSingleScreen(unsigned int screenNum) { osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); @@ -419,7 +475,8 @@ void View::setUpViewOnSingleScreen(unsigned int screenNum) traits->sharedContext = 0; traits->sampleBuffers = ds->getMultiSamples(); traits->samples = ds->getNumMultiSamples(); - if (ds->getStereo() && (ds->getStereoMode() == osg::DisplaySettings::QUAD_BUFFER)) { + if (ds->getStereo() && (ds->getStereoMode() == osg::DisplaySettings::QUAD_BUFFER)) + { traits->quadBufferStereo = true; } diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index e0e7721a3..11999f021 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -617,6 +617,24 @@ Viewer::Viewer(osg::ArgumentParser& arguments) if( cnt==3 || cnt==4 ) getCamera()->setClearColor( osg::Vec4(r,g,b,a) ); else osg::notify(osg::WARN)<<"Invalid clear color \""<0 && height>0) + { + if (screenNum>=0) setUpViewInWindow(x, y, width, height, screenNum); + else setUpViewInWindow(x,y,width,height); + + } + else if (screenNum>=0) + { + setUpViewOnSingleScreen(screenNum); + } + } void Viewer::constructorInit()