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

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
RevLine 
[6941]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.
[1818]17*/
18
19#include <osgDB/ReadFile>
20#include <osgUtil/Optimizer>
[5962]21#include <osgViewer/Viewer>
[6941]22
23
[5964]24#include <iostream>
[1818]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
[5962]31    // read the scene from the list of file specified commandline args.
32    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
[1818]33
[6916]34    // if not loaded assume no arguments passed in, try use default mode instead.
[12529]35    if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt");
[6916]36   
[5962]37    // if no model has been successfully loaded report failure.
38    if (!loadedModel)
[1818]39    {
[5962]40        std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
[1818]41        return 1;
42    }
43
[5962]44    // construct the viewer.
45    osgViewer::Viewer viewer;
[1818]46
[7065]47    int xoffset = 40;
48    int yoffset = 40;
49
[5962]50    // left window + left slave camera
[1818]51    {
[5962]52        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
[7065]53        traits->x = xoffset + 0;
54        traits->y = yoffset + 0;
55        traits->width = 600;
[5962]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
[7065]70        // add this slave camera to the viewer, with a shift left of the projection matrix
[5962]71        viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0,0.0,0.0), osg::Matrixd());
[1818]72    }
73   
[7065]74    // right window + right slave camera
[1818]75    {
[5962]76        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
[7065]77        traits->x = xoffset + 600;
78        traits->y = yoffset + 0;
79        traits->width = 600;
[5962]80        traits->height = 480;
81        traits->windowDecoration = true;
82        traits->doubleBuffer = true;
83        traits->sharedContext = 0;
[1818]84
[5962]85        osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
[1818]86
[5962]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
[7065]94        // add this slave camera to the viewer, with a shift right of the projection matrix
[5962]95        viewer.addSlave(camera.get(), osg::Matrixd::translate(-1.0,0.0,0.0), osg::Matrixd());
[1818]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
[5962]106    return viewer.run();
[1818]107}
Note: See TracBrowser for help on using the browser.