Added osgViewer::View::setUpViewInWindow(...) method and command line option into
osgViewer::Viewer to allow you to specify the window dimentions and screen for the window on startup.
This commit is contained in:
@@ -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<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
if (!loadedModel)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<osg::GraphicsContext> 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<osg::GraphicsContext::Traits> 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<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
||||
|
||||
_camera->setGraphicsContext(gc.get());
|
||||
|
||||
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
|
||||
if (gw)
|
||||
{
|
||||
osg::notify(osg::INFO)<<"View::setUpViewOnSingleScreen - GraphicsWindow has been created successfully."<<std::endl;
|
||||
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(x, y, width, height );
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
|
||||
}
|
||||
|
||||
double fovy, aspectRatio, zNear, zFar;
|
||||
_camera->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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 \""<<colorStr<<"\""<<std::endl;
|
||||
}
|
||||
|
||||
int screenNum = -1;
|
||||
while (arguments.read("--screen",screenNum)) {}
|
||||
|
||||
int x = -1, y = -1, width = -1, height = -1;
|
||||
while (arguments.read("--window",x,y,width,height)) {}
|
||||
|
||||
if (width>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()
|
||||
|
||||
Reference in New Issue
Block a user