2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-04-07 18:20:34 +08:00
|
|
|
*
|
|
|
|
* This application is open source and may be redistributed and/or modified
|
|
|
|
* freely and without restriction, both in commericial and non commericial applications,
|
|
|
|
* as long as this copyright notice is maintained.
|
|
|
|
*
|
|
|
|
* This application is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <osgDB/ReadFile>
|
|
|
|
#include <osgUtil/Optimizer>
|
2007-01-11 23:19:59 +08:00
|
|
|
#include <osgViewer/Viewer>
|
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.
|
|
|
|
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
2003-04-07 18:20:34 +08:00
|
|
|
|
2007-01-11 23:19:59 +08:00
|
|
|
// if no model has been successfully loaded report failure.
|
|
|
|
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-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;
|
|
|
|
traits->x = 0;
|
|
|
|
traits->y = 0;
|
|
|
|
traits->width = 640;
|
|
|
|
traits->height = 480;
|
|
|
|
traits->windowDecoration = true;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// add this slave camra to the viewer, with a shift left of the projection matrix
|
|
|
|
viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0,0.0,0.0), osg::Matrixd());
|
2003-04-07 18:20:34 +08:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
traits->x = 640;
|
|
|
|
traits->y = 0;
|
|
|
|
traits->width = 640;
|
|
|
|
traits->height = 480;
|
|
|
|
traits->windowDecoration = true;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// add this slave camra to the viewer, with a shift right of the projection matrix
|
|
|
|
viewer.addSlave(camera.get(), osg::Matrixd::translate(-1.0,0.0,0.0), osg::Matrixd());
|
2003-04-07 18:20:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// optimize the scene graph, remove rendundent nodes and state etc.
|
|
|
|
osgUtil::Optimizer optimizer;
|
|
|
|
optimizer.optimize(loadedModel.get());
|
|
|
|
|
|
|
|
// set the scene to render
|
|
|
|
viewer.setSceneData(loadedModel.get());
|
|
|
|
|
2007-01-11 23:19:59 +08:00
|
|
|
return viewer.run();
|
2003-04-07 18:20:34 +08:00
|
|
|
}
|
|
|
|
|