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

Revision 5964, 3.3 kB (checked in by robert, 7 years ago)

Added #include <iostream>

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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 <osgViewer/Viewer>
15#include <iostream>
16
17int main( int argc, char **argv )
18{
19    // use an ArgumentParser object to manage the program arguments.
20    osg::ArgumentParser arguments(&argc,argv);
21
22    // read the scene from the list of file specified commandline args.
23    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
24
25    // if no model has been successfully loaded report failure.
26    if (!loadedModel)
27    {
28        std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
29        return 1;
30    }
31
32    // construct the viewer.
33    osgViewer::Viewer viewer;
34
35    // left window + left slave camera
36    {
37        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
38        traits->x = 0;
39        traits->y = 0;
40        traits->width = 640;
41        traits->height = 480;
42        traits->windowDecoration = true;
43        traits->doubleBuffer = true;
44        traits->sharedContext = 0;
45
46        osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
47
48        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
49        camera->setGraphicsContext(gc.get());
50        camera->setViewport(new osg::Viewport(0,0, traits->width, traits->height));
51        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
52        camera->setDrawBuffer(buffer);
53        camera->setReadBuffer(buffer);
54
55        // add this slave camra to the viewer, with a shift left of the projection matrix
56        viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0,0.0,0.0), osg::Matrixd());
57    }
58   
59    // left window + left slave camera
60    {
61        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
62        traits->x = 640;
63        traits->y = 0;
64        traits->width = 640;
65        traits->height = 480;
66        traits->windowDecoration = true;
67        traits->doubleBuffer = true;
68        traits->sharedContext = 0;
69
70        osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
71
72        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
73        camera->setGraphicsContext(gc.get());
74        camera->setViewport(new osg::Viewport(0,0, traits->width, traits->height));
75        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
76        camera->setDrawBuffer(buffer);
77        camera->setReadBuffer(buffer);
78
79        // add this slave camra to the viewer, with a shift right of the projection matrix
80        viewer.addSlave(camera.get(), osg::Matrixd::translate(-1.0,0.0,0.0), osg::Matrixd());
81    }
82
83
84    // optimize the scene graph, remove rendundent nodes and state etc.
85    osgUtil::Optimizer optimizer;
86    optimizer.optimize(loadedModel.get());
87
88    // set the scene to render
89    viewer.setSceneData(loadedModel.get());
90
91    return viewer.run();
92}
Note: See TracBrowser for help on using the browser.