root/OpenSceneGraph/trunk/examples/osgwindows/osgwindows.cpp @ 1892

Revision 1892, 4.5 kB (checked in by don, 11 years ago)

InputRectangle? converted to RenderSurface?->get()...

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
2 *
3 * This application is open source and may be redistributed and/or modified   
4 * freely and without restriction, both in commericial and non commericial applications,
5 * as long as this copyright notice is maintained.
6 *
7 * This application is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10*/
11
12#include <osgDB/ReadFile>
13#include <osgUtil/Optimizer>
14#include <osgProducer/Viewer>
15
16static Producer::CameraConfig *BuildConfig(void)
17{
18    Producer::RenderSurface *rs1 = new Producer::RenderSurface;
19    rs1->setScreenNum(0);
20    //rs1->useBorder(false);
21    rs1->setWindowRectangle(0,0,640,480);
22    Producer::Camera *camera1 = new Producer::Camera;
23    camera1->setRenderSurface(rs1);
24    camera1->setOffset( 1.0, 0.0 );
25
26    Producer::RenderSurface *rs2 = new Producer::RenderSurface;
27    rs2->setScreenNum(0);
28    //rs2->useBorder(false);
29    rs2->setWindowRectangle(640,0,640,480);
30    Producer::Camera *camera2 = new Producer::Camera;
31    camera2->setRenderSurface(rs2);
32    camera2->setOffset( -1.0, 0.0 );
33
34    rs1->setInputRectangle( Producer::RenderSurface::InputRectangle(0.0,0.5,0.0,1.0));
35    rs2->setInputRectangle( Producer::RenderSurface::InputRectangle(0.5,1.0,0.0,1.0));
36
37    Producer::InputArea *ia = new Producer::InputArea;
38    ia->addRenderSurface(rs1);
39    ia->addRenderSurface(rs2);
40
41    Producer::CameraConfig *cfg = new Producer::CameraConfig;
42    cfg->addCamera("Camera 1",camera1);
43    cfg->addCamera("Camera 2", camera2);
44    cfg->setInputArea(ia);
45    return cfg;
46}
47
48int main( int argc, char **argv )
49{
50
51    // use an ArgumentParser object to manage the program arguments.
52    osg::ArgumentParser arguments(&argc,argv);
53   
54    // set up the usage document, in case we need to print out how to use this program.
55    arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
56    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrate hows to set up programitically a Producer::CameraConfig and use it to set up multiple window views.");
57    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
58    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
59   
60
61    // construct the viewer.
62    osgProducer::Viewer viewer(BuildConfig());
63
64    // set up the value with sensible default event handlers.
65    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
66
67    // get details on keyboard and mouse bindings used by the viewer.
68    viewer.getUsage(*arguments.getApplicationUsage());
69
70    // if user request help write it out to cout.
71    if (arguments.read("-h") || arguments.read("--help"))
72    {
73        arguments.getApplicationUsage()->write(std::cout);
74        return 1;
75    }
76
77    // any option left unread are converted into errors to write out later.
78    arguments.reportRemainingOptionsAsUnrecognized();
79
80    // report any errors if they have occured when parsing the program aguments.
81    if (arguments.errors())
82    {
83        arguments.writeErrorMessages(std::cout);
84        return 1;
85    }
86   
87    if (arguments.argc()<=1)
88    {
89        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
90        return 1;
91    }
92
93    // read the scene from the list of file specified commandline args.
94    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
95
96    // if no model has been successfully loaded report failure.
97    if (!loadedModel)
98    {
99        std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
100        return 1;
101    }
102
103
104    // optimize the scene graph, remove rendundent nodes and state etc.
105    osgUtil::Optimizer optimizer;
106    optimizer.optimize(loadedModel.get());
107
108    // set the scene to render
109    viewer.setSceneData(loadedModel.get());
110
111    // create the windows and run the threads.
112    viewer.realize();
113
114    while( !viewer.done() )
115    {
116        // wait for all cull and draw threads to complete.
117        viewer.sync();
118
119        // update the scene by traversing it with the the update visitor which will
120        // call all node update callbacks and animations.
121        viewer.update();
122         
123        // fire off the cull and draw traversals of the scene.
124        viewer.frame();
125       
126    }
127   
128    // wait for all cull and draw threads to complete before exit.
129    viewer.sync();
130
131    return 0;
132}
Note: See TracBrowser for help on using the browser.