Made the custom window set up a runtime option
This commit is contained in:
parent
a42633a9ee
commit
348fc7bdb3
@ -114,105 +114,85 @@ int main( int argc, char **argv )
|
|||||||
// construct the viewer.
|
// construct the viewer.
|
||||||
osgViewer::Viewer viewer;
|
osgViewer::Viewer viewer;
|
||||||
|
|
||||||
viewer.setCameraManipulator(new GliderManipulator());
|
|
||||||
|
|
||||||
// if user request help write it out to cout.
|
// if user request help write it out to cout.
|
||||||
if (arguments.read("-h") || arguments.read("--help"))
|
if (arguments.read("-h") || arguments.read("--help"))
|
||||||
{
|
{
|
||||||
arguments.getApplicationUsage()->write(std::cout);
|
arguments.getApplicationUsage()->write(std::cout);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// any option left unread are converted into errors to write out later.
|
|
||||||
arguments.reportRemainingOptionsAsUnrecognized();
|
|
||||||
|
|
||||||
// report any errors if they have occured when parsing the program aguments.
|
|
||||||
if (arguments.errors())
|
|
||||||
{
|
|
||||||
arguments.writeErrorMessages(std::cout);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// load the nodes from the commandline arguments.
|
bool customWindows = false;
|
||||||
osg::Node* rootnode = osgDB::readNodeFiles(arguments);
|
while(arguments.read("-1")) customWindows = true;
|
||||||
if (!rootnode) rootnode = createModel();
|
while(arguments.read("-2")) customWindows = false;
|
||||||
|
|
||||||
viewer.setSceneData( rootnode );
|
if (customWindows)
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
|
||||||
if (!wsi)
|
|
||||||
{
|
{
|
||||||
osg::notify(osg::NOTICE)<<"View::setUpViewAcrossAllScreens() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
||||||
return 0;
|
if (!wsi)
|
||||||
}
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<"View::setUpViewAcrossAllScreens() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
||||||
unsigned int width, height;
|
return 0;
|
||||||
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
|
}
|
||||||
|
|
||||||
width -= 500;
|
unsigned int width, height;
|
||||||
height -= 500;
|
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
|
||||||
|
|
||||||
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
width -= 500;
|
||||||
traits->x = 500;
|
height -= 500;
|
||||||
traits->y = 500;
|
|
||||||
traits->width = width;
|
|
||||||
traits->height = height;
|
|
||||||
#if 0
|
|
||||||
traits->windowDecoration = false;
|
|
||||||
#else
|
|
||||||
traits->windowDecoration = true;
|
|
||||||
#endif
|
|
||||||
traits->doubleBuffer = true;
|
|
||||||
traits->sharedContext = 0;
|
|
||||||
|
|
||||||
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
||||||
|
traits->x = 500;
|
||||||
|
traits->y = 500;
|
||||||
|
traits->width = width;
|
||||||
|
traits->height = height;
|
||||||
|
#if 0
|
||||||
|
traits->windowDecoration = false;
|
||||||
|
#else
|
||||||
|
traits->windowDecoration = true;
|
||||||
|
#endif
|
||||||
|
traits->doubleBuffer = true;
|
||||||
|
traits->sharedContext = 0;
|
||||||
|
|
||||||
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
|
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
||||||
if (gw)
|
|
||||||
{
|
|
||||||
osg::notify(osg::NOTICE)<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
|
|
||||||
|
|
||||||
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height );
|
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
|
||||||
}
|
if (gw)
|
||||||
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
|
||||||
|
|
||||||
|
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int numCameras = 2;
|
||||||
|
double aspectRatioScale = 1.0/(double)numCameras;
|
||||||
|
for(unsigned int i=0; i<numCameras;++i)
|
||||||
|
{
|
||||||
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||||
|
camera->setGraphicsContext(gc.get());
|
||||||
|
camera->setViewport(new osg::Viewport((i*width)/numCameras,(i*height)/numCameras, width/numCameras, height/numCameras));
|
||||||
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
||||||
|
camera->setDrawBuffer(buffer);
|
||||||
|
camera->setReadBuffer(buffer);
|
||||||
|
|
||||||
|
viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::scale(aspectRatioScale,1.0,1.0));
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
|
viewer.setUpViewAcrossAllScreens();
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int numCameras = 2;
|
|
||||||
double aspectRatioScale = 1.0/(double)numCameras;
|
|
||||||
for(unsigned int i=0; i<numCameras;++i)
|
|
||||||
{
|
|
||||||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
||||||
camera->setGraphicsContext(gc.get());
|
|
||||||
camera->setViewport(new osg::Viewport((i*width)/numCameras,(i*height)/numCameras, width/numCameras, height/numCameras));
|
|
||||||
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
||||||
camera->setDrawBuffer(buffer);
|
|
||||||
camera->setReadBuffer(buffer);
|
|
||||||
|
|
||||||
viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::scale(aspectRatioScale,1.0,1.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
viewer.setUpRenderingSupport();
|
|
||||||
viewer.assignSceneDataToCameras();
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
viewer.setUpViewAcrossAllScreens();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
viewer.realize();
|
|
||||||
|
|
||||||
while( !viewer.done() )
|
|
||||||
{
|
|
||||||
// fire off the cull and draw traversals of the scene.
|
|
||||||
viewer.frame();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
// set up the camera manipulation with out custom manipultor
|
||||||
|
viewer.setCameraManipulator(new GliderManipulator());
|
||||||
|
|
||||||
|
// pass the scene graph to the viewer
|
||||||
|
viewer.setSceneData( createModel() );
|
||||||
|
|
||||||
|
return viewer.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user