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

Revision 12529, 4.0 kB (checked in by robert, 3 years ago)

Replaced .osg with .osgt file usage

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* OpenSceneGraph example, osgwindows.
2*
3*  Permission is hereby granted, free of charge, to any person obtaining a copy
4*  of this software and associated documentation files (the "Software"), to deal
5*  in the Software without restriction, including without limitation the rights
6*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*  copies of the Software, and to permit persons to whom the Software is
8*  furnished to do so, subject to the following conditions:
9*
10*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
16*  THE SOFTWARE.
17*/
18
19#include <osgDB/ReadFile>
20#include <osgUtil/Optimizer>
21#include <osgViewer/Viewer>
22
23
24#include <iostream>
25
26int main( int argc, char **argv )
27{
28    // use an ArgumentParser object to manage the program arguments.
29    osg::ArgumentParser arguments(&argc,argv);
30
31    // read the scene from the list of file specified commandline args.
32    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
33
34    // if not loaded assume no arguments passed in, try use default mode instead.
35    if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt");
36   
37    // if no model has been successfully loaded report failure.
38    if (!loadedModel)
39    {
40        std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
41        return 1;
42    }
43
44    // construct the viewer.
45    osgViewer::Viewer viewer;
46
47    int xoffset = 40;
48    int yoffset = 40;
49
50    // left window + left slave camera
51    {
52        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
53        traits->x = xoffset + 0;
54        traits->y = yoffset + 0;
55        traits->width = 600;
56        traits->height = 480;
57        traits->windowDecoration = true;
58        traits->doubleBuffer = true;
59        traits->sharedContext = 0;
60
61        osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
62
63        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
64        camera->setGraphicsContext(gc.get());
65        camera->setViewport(new osg::Viewport(0,0, traits->width, traits->height));
66        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
67        camera->setDrawBuffer(buffer);
68        camera->setReadBuffer(buffer);
69
70        // add this slave camera to the viewer, with a shift left of the projection matrix
71        viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0,0.0,0.0), osg::Matrixd());
72    }
73   
74    // right window + right slave camera
75    {
76        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
77        traits->x = xoffset + 600;
78        traits->y = yoffset + 0;
79        traits->width = 600;
80        traits->height = 480;
81        traits->windowDecoration = true;
82        traits->doubleBuffer = true;
83        traits->sharedContext = 0;
84
85        osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
86
87        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
88        camera->setGraphicsContext(gc.get());
89        camera->setViewport(new osg::Viewport(0,0, traits->width, traits->height));
90        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
91        camera->setDrawBuffer(buffer);
92        camera->setReadBuffer(buffer);
93
94        // add this slave camera to the viewer, with a shift right of the projection matrix
95        viewer.addSlave(camera.get(), osg::Matrixd::translate(-1.0,0.0,0.0), osg::Matrixd());
96    }
97
98
99    // optimize the scene graph, remove rendundent nodes and state etc.
100    osgUtil::Optimizer optimizer;
101    optimizer.optimize(loadedModel.get());
102
103    // set the scene to render
104    viewer.setSceneData(loadedModel.get());
105
106    return viewer.run();
107}
Note: See TracBrowser for help on using the browser.