2007-06-12 22:20:16 +08:00
|
|
|
/* OpenSceneGraph example, osgwindows.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
2003-04-07 18:20:34 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <osgDB/ReadFile>
|
|
|
|
#include <osgUtil/Optimizer>
|
2007-01-11 23:19:59 +08:00
|
|
|
#include <osgViewer/Viewer>
|
2007-06-12 22:20:16 +08:00
|
|
|
|
|
|
|
|
2007-01-11 23:53:32 +08:00
|
|
|
#include <iostream>
|
2003-04-07 18:20:34 +08:00
|
|
|
|
|
|
|
int main( int argc, char **argv )
|
|
|
|
{
|
|
|
|
// use an ArgumentParser object to manage the program arguments.
|
|
|
|
osg::ArgumentParser arguments(&argc,argv);
|
|
|
|
|
2007-01-11 23:19:59 +08:00
|
|
|
// read the scene from the list of file specified commandline args.
|
2015-10-22 21:42:19 +08:00
|
|
|
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
2003-04-07 18:20:34 +08:00
|
|
|
|
2007-06-08 23:37:20 +08:00
|
|
|
// if not loaded assume no arguments passed in, try use default mode instead.
|
2015-10-22 21:42:19 +08:00
|
|
|
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cow.osgt");
|
|
|
|
|
2007-01-11 23:19:59 +08:00
|
|
|
// if no model has been successfully loaded report failure.
|
2015-10-22 21:42:19 +08:00
|
|
|
if (!loadedModel)
|
2003-04-07 18:20:34 +08:00
|
|
|
{
|
2007-01-11 23:19:59 +08:00
|
|
|
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
2003-04-07 18:20:34 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-01-11 23:19:59 +08:00
|
|
|
// construct the viewer.
|
|
|
|
osgViewer::Viewer viewer;
|
2003-04-07 18:20:34 +08:00
|
|
|
|
2007-07-04 01:32:19 +08:00
|
|
|
int xoffset = 40;
|
|
|
|
int yoffset = 40;
|
|
|
|
|
2007-01-11 23:19:59 +08:00
|
|
|
// left window + left slave camera
|
2003-04-07 18:20:34 +08:00
|
|
|
{
|
2007-01-11 23:19:59 +08:00
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
2016-05-16 20:45:31 +08:00
|
|
|
|
2007-07-04 01:32:19 +08:00
|
|
|
traits->x = xoffset + 0;
|
|
|
|
traits->y = yoffset + 0;
|
|
|
|
traits->width = 600;
|
2007-01-11 23:19:59 +08:00
|
|
|
traits->height = 480;
|
|
|
|
traits->windowDecoration = true;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
2018-09-09 00:18:33 +08:00
|
|
|
traits->readDISPLAY();
|
|
|
|
traits->setUndefinedScreenDetailsToDefaultScreen();
|
2007-01-11 23:19:59 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
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);
|
|
|
|
|
2007-07-04 01:32:19 +08:00
|
|
|
// add this slave camera to the viewer, with a shift left of the projection matrix
|
2007-01-11 23:19:59 +08:00
|
|
|
viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0,0.0,0.0), osg::Matrixd());
|
2003-04-07 18:20:34 +08:00
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2007-07-04 01:32:19 +08:00
|
|
|
// right window + right slave camera
|
2003-04-07 18:20:34 +08:00
|
|
|
{
|
2007-01-11 23:19:59 +08:00
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
2007-07-04 01:32:19 +08:00
|
|
|
traits->x = xoffset + 600;
|
|
|
|
traits->y = yoffset + 0;
|
|
|
|
traits->width = 600;
|
2007-01-11 23:19:59 +08:00
|
|
|
traits->height = 480;
|
|
|
|
traits->windowDecoration = true;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
2018-09-09 00:18:33 +08:00
|
|
|
traits->readDISPLAY();
|
|
|
|
traits->setUndefinedScreenDetailsToDefaultScreen();
|
2007-01-11 23:19:59 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
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);
|
|
|
|
|
2007-07-04 01:32:19 +08:00
|
|
|
// add this slave camera to the viewer, with a shift right of the projection matrix
|
2007-01-11 23:19:59 +08:00
|
|
|
viewer.addSlave(camera.get(), osg::Matrixd::translate(-1.0,0.0,0.0), osg::Matrixd());
|
2003-04-07 18:20:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-13 18:43:56 +08:00
|
|
|
// optimize the scene graph, remove redundant nodes and state etc.
|
2003-04-07 18:20:34 +08:00
|
|
|
osgUtil::Optimizer optimizer;
|
2015-10-22 21:42:19 +08:00
|
|
|
optimizer.optimize(loadedModel);
|
2003-04-07 18:20:34 +08:00
|
|
|
|
|
|
|
// set the scene to render
|
2015-10-22 21:42:19 +08:00
|
|
|
viewer.setSceneData(loadedModel);
|
2003-04-07 18:20:34 +08:00
|
|
|
|
2007-01-11 23:19:59 +08:00
|
|
|
return viewer.run();
|
2003-04-07 18:20:34 +08:00
|
|
|
}
|
|
|
|
|