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

Revision 1898, 4.6 kB (checked in by robert, 11 years ago)

Added setting of the RenderSurface? name to the application name.

  • 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->setWindowName("osgwindows");
21    //rs1->useBorder(false);
22    rs1->setWindowRectangle(0,0,640,480);
23    Producer::Camera *camera1 = new Producer::Camera;
24    camera1->setRenderSurface(rs1);
25    camera1->setOffset( 1.0, 0.0 );
26
27    Producer::RenderSurface *rs2 = new Producer::RenderSurface;
28    rs2->setScreenNum(0);
29    rs2->setWindowName("osgwindows");
30    //rs2->useBorder(false);
31    rs2->setWindowRectangle(640,0,640,480);
32    Producer::Camera *camera2 = new Producer::Camera;
33    camera2->setRenderSurface(rs2);
34    camera2->setOffset( -1.0, 0.0 );
35
36    rs1->setInputRectangle( Producer::RenderSurface::InputRectangle(0.0,0.5,0.0,1.0));
37    rs2->setInputRectangle( Producer::RenderSurface::InputRectangle(0.5,1.0,0.0,1.0));
38
39    Producer::InputArea *ia = new Producer::InputArea;
40    ia->addRenderSurface(rs1);
41    ia->addRenderSurface(rs2);
42
43    Producer::CameraConfig *cfg = new Producer::CameraConfig;
44    cfg->addCamera("Camera 1",camera1);
45    cfg->addCamera("Camera 2", camera2);
46    cfg->setInputArea(ia);
47    return cfg;
48}
49
50int main( int argc, char **argv )
51{
52
53    // use an ArgumentParser object to manage the program arguments.
54    osg::ArgumentParser arguments(&argc,argv);
55   
56    // set up the usage document, in case we need to print out how to use this program.
57    arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
58    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.");
59    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
60    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
61   
62
63    // construct the viewer.
64    osgProducer::Viewer viewer(BuildConfig());
65
66    // set up the value with sensible default event handlers.
67    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
68
69    // get details on keyboard and mouse bindings used by the viewer.
70    viewer.getUsage(*arguments.getApplicationUsage());
71
72    // if user request help write it out to cout.
73    if (arguments.read("-h") || arguments.read("--help"))
74    {
75        arguments.getApplicationUsage()->write(std::cout);
76        return 1;
77    }
78
79    // any option left unread are converted into errors to write out later.
80    arguments.reportRemainingOptionsAsUnrecognized();
81
82    // report any errors if they have occured when parsing the program aguments.
83    if (arguments.errors())
84    {
85        arguments.writeErrorMessages(std::cout);
86        return 1;
87    }
88   
89    if (arguments.argc()<=1)
90    {
91        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
92        return 1;
93    }
94
95    // read the scene from the list of file specified commandline args.
96    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
97
98    // if no model has been successfully loaded report failure.
99    if (!loadedModel)
100    {
101        std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
102        return 1;
103    }
104
105
106    // optimize the scene graph, remove rendundent nodes and state etc.
107    osgUtil::Optimizer optimizer;
108    optimizer.optimize(loadedModel.get());
109
110    // set the scene to render
111    viewer.setSceneData(loadedModel.get());
112
113    // create the windows and run the threads.
114    viewer.realize();
115
116    while( !viewer.done() )
117    {
118        // wait for all cull and draw threads to complete.
119        viewer.sync();
120
121        // update the scene by traversing it with the the update visitor which will
122        // call all node update callbacks and animations.
123        viewer.update();
124         
125        // fire off the cull and draw traversals of the scene.
126        viewer.frame();
127       
128    }
129   
130    // wait for all cull and draw threads to complete before exit.
131    viewer.sync();
132
133    return 0;
134}
Note: See TracBrowser for help on using the browser.