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

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

Ported following examples to osgViewer:

osgteapot
osgtessellate
osgtext
osgtexture1D
osgtexture2D
osgtexture3D
osgtexturerectangle
osgvertexprogram
osgvolume
osgwindows
osgsimple
osgkeyboardmouse

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