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

Revision 5064, 5.8 kB (checked in by robert, 9 years ago)

Build fixes to cope with changes to Producer/osgProducer.

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