2007-01-05 23:54:13 +08:00
|
|
|
#if 1
|
2005-08-18 00:13:06 +08:00
|
|
|
|
2005-08-16 21:29:07 +08:00
|
|
|
#include <osgDB/ReadFile>
|
2006-12-20 00:12:29 +08:00
|
|
|
#include <osgViewer/Viewer>
|
2006-12-21 05:13:29 +08:00
|
|
|
#include <osgGA/TrackballManipulator>
|
2007-01-03 01:39:31 +08:00
|
|
|
#include <osgGA/AnimationPathManipulator>
|
2006-12-23 01:46:21 +08:00
|
|
|
#include <iostream>
|
2006-12-20 00:12:29 +08:00
|
|
|
|
2007-01-03 01:39:31 +08:00
|
|
|
void singleWindowMultipleCameras(osgViewer::Viewer& viewer)
|
2006-12-20 00:12:29 +08:00
|
|
|
{
|
2007-01-02 02:20:10 +08:00
|
|
|
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
|
|
|
if (!wsi)
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"View::setUpViewAcrossAllScreens() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
2007-01-03 01:39:31 +08:00
|
|
|
return;
|
2007-01-02 02:20:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int width, height;
|
|
|
|
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
|
|
|
traits->x = 0;
|
|
|
|
traits->y = 0;
|
|
|
|
traits->width = width;
|
|
|
|
traits->height = height;
|
|
|
|
traits->windowDecoration = true;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
2007-01-06 00:46:57 +08:00
|
|
|
if (gc.valid())
|
2007-01-02 02:20:10 +08:00
|
|
|
{
|
2007-01-06 00:46:57 +08:00
|
|
|
osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."<<std::endl;
|
2007-01-02 02:20:10 +08:00
|
|
|
|
2007-01-06 00:46:57 +08:00
|
|
|
// need to ensure that the window is cleared make sure that the complete window is set the correct colour
|
|
|
|
// rather than just the parts of the window that are under the camera's viewports
|
|
|
|
gc->setClearColor(osg::Vec4f(0.2f,0.2f,0.6f,1.0f));
|
|
|
|
gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2007-01-02 02:20:10 +08:00
|
|
|
}
|
|
|
|
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));
|
|
|
|
}
|
2007-01-03 01:39:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void multipleWindowMultipleCameras(osgViewer::Viewer& viewer)
|
|
|
|
{
|
|
|
|
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
|
|
|
if (!wsi)
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"View::setUpViewAcrossAllScreens() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int width, height;
|
|
|
|
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
|
|
|
|
|
|
|
|
|
2007-01-09 03:29:59 +08:00
|
|
|
unsigned int numCameras = 6;
|
2007-01-03 01:39:31 +08:00
|
|
|
double aspectRatioScale = (double)numCameras;
|
|
|
|
double translate_x = double(numCameras)-1;
|
|
|
|
for(unsigned int i=0; i<numCameras;++i, translate_x -= 2.0)
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
2007-01-09 03:29:59 +08:00
|
|
|
traits->screenNum = i / 3;
|
2007-01-03 01:39:31 +08:00
|
|
|
traits->x = (i*width)/numCameras;
|
|
|
|
traits->y = 0;
|
|
|
|
traits->width = width/numCameras-1;
|
|
|
|
traits->height = height;
|
|
|
|
traits->windowDecoration = true;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
2007-01-06 00:46:57 +08:00
|
|
|
if (gc.valid())
|
2007-01-03 01:39:31 +08:00
|
|
|
{
|
2007-01-06 00:46:57 +08:00
|
|
|
osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."<<std::endl;
|
2007-01-03 01:39:31 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setViewport(new osg::Viewport(0,0, width/numCameras, height));
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
|
|
|
|
viewer.addSlave(camera.get(), osg::Matrix::scale(aspectRatioScale, 1.0, 1.0)*osg::Matrix::translate(translate_x, 0.0, 0.0), osg::Matrix() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main( int argc, char **argv )
|
|
|
|
{
|
|
|
|
// use an ArgumentParser object to manage the program arguments.
|
|
|
|
osg::ArgumentParser arguments(&argc,argv);
|
|
|
|
|
|
|
|
if (argc<2)
|
|
|
|
{
|
|
|
|
std::cout << argv[0] <<": requires filename argument." << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string pathfile;
|
|
|
|
osg::ref_ptr<osgGA::AnimationPathManipulator> apm = 0;
|
|
|
|
while (arguments.read("-p",pathfile))
|
|
|
|
{
|
|
|
|
apm = new osgGA::AnimationPathManipulator(pathfile);
|
2007-01-13 05:05:39 +08:00
|
|
|
if (!apm.valid() || !(apm->valid()) )
|
2007-01-03 01:39:31 +08:00
|
|
|
{
|
|
|
|
apm = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
osgViewer::Viewer viewer;
|
|
|
|
|
|
|
|
while (arguments.read("-s")) { viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); }
|
|
|
|
while (arguments.read("-g")) { viewer.setThreadingModel(osgViewer::Viewer::ThreadPerContext); }
|
|
|
|
while (arguments.read("-c")) { viewer.setThreadingModel(osgViewer::Viewer::ThreadPerCamera); }
|
2007-01-05 05:58:37 +08:00
|
|
|
|
|
|
|
bool limitNumberOfFrames = false;
|
|
|
|
unsigned int maxFrames = 10;
|
|
|
|
while (arguments.read("--run-till-frame-number",maxFrames)) { limitNumberOfFrames = true; }
|
|
|
|
|
|
|
|
// alternative viewer window setups.
|
|
|
|
while (arguments.read("-1")) { singleWindowMultipleCameras(viewer); }
|
|
|
|
while (arguments.read("-2")) { multipleWindowMultipleCameras(viewer); }
|
2007-01-03 01:39:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
if (apm.valid()) viewer.setCameraManipulator(apm.get());
|
|
|
|
else viewer.setCameraManipulator( new osgGA::TrackballManipulator() );
|
|
|
|
|
2007-01-05 05:58:37 +08:00
|
|
|
// load the scene.
|
|
|
|
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
|
|
|
if (!loadedModel)
|
|
|
|
{
|
|
|
|
std::cout << argv[0] <<": No data loaded." << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2007-01-05 05:51:10 +08:00
|
|
|
|
|
|
|
viewer.setSceneData(loadedModel.get());
|
|
|
|
|
2007-01-09 00:20:10 +08:00
|
|
|
// viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
|
|
|
|
|
|
|
|
viewer.realize();
|
2006-12-20 00:12:29 +08:00
|
|
|
|
2006-12-23 05:53:44 +08:00
|
|
|
unsigned int numFrames = 0;
|
2006-12-25 00:40:19 +08:00
|
|
|
while(!viewer.done() && !(limitNumberOfFrames && numFrames>=maxFrames))
|
2006-12-22 00:56:20 +08:00
|
|
|
{
|
|
|
|
viewer.frame();
|
2006-12-23 05:53:44 +08:00
|
|
|
++numFrames;
|
2006-12-20 00:12:29 +08:00
|
|
|
}
|
2006-12-22 00:56:20 +08:00
|
|
|
|
2005-08-16 21:29:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2007-01-05 23:54:13 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
#include <osgViewer/Viewer>
|
|
|
|
#include <osgDB/ReadFile>
|
2007-01-09 00:20:10 +08:00
|
|
|
#include <osgDB/WriteFile>
|
2007-01-05 23:54:13 +08:00
|
|
|
|
|
|
|
int main( int, char **)
|
|
|
|
{
|
2007-01-09 05:19:33 +08:00
|
|
|
osg::ref_ptr<osg::Node> model = osgDB::readNodeFile("cow.osg");
|
2007-01-09 00:20:10 +08:00
|
|
|
|
|
|
|
for(unsigned int i=0; i<5; ++i)
|
|
|
|
{
|
2007-01-09 05:19:33 +08:00
|
|
|
osg::notify(osg::NOTICE)<<"New frame *******************************"<<std::endl;
|
|
|
|
|
2007-01-09 00:20:10 +08:00
|
|
|
osgViewer::Viewer viewer;
|
|
|
|
viewer.setSceneData(model.get());
|
|
|
|
viewer.run();
|
2007-01-09 05:19:33 +08:00
|
|
|
osg::notify(osg::NOTICE)<<std::endl<<std::endl;
|
2007-01-09 00:20:10 +08:00
|
|
|
}
|
2007-01-09 05:19:33 +08:00
|
|
|
return 0;
|
2007-01-05 23:54:13 +08:00
|
|
|
}
|
2007-01-09 00:20:10 +08:00
|
|
|
|
2007-01-05 23:54:13 +08:00
|
|
|
#endif
|