root/OpenSceneGraph/trunk/examples/osgscribe/osgscribe.cpp @ 1832

Revision 1832, 4.5 kB (checked in by robert, 11 years ago)

Changed the Viewer::realize() calls across to not using the threading paramter
leaving it up to the Viewer to specify the mode (which by default is MultiThreaded?).
Added a check for the presence of osgParticle systems so that threading is
disabled in this case.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#include <osg/Geode>
2#include <osg/Group>
3#include <osg/Notify>
4#include <osg/Material>
5#include <osg/PolygonOffset>
6#include <osg/PolygonMode>
7#include <osg/LineStipple>
8
9#include <osgDB/Registry>
10#include <osgDB/ReadFile>
11
12#include <osgProducer/Viewer>
13
14#include <osgUtil/Optimizer>
15
16int main( int argc, char **argv )
17{
18
19    // use an ArgumentParser object to manage the program arguments.
20    osg::ArgumentParser arguments(&argc,argv);
21
22    // set up the usage document, in case we need to print out how to use this program.
23    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
24    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
25   
26    // construct the viewer.
27    osgProducer::Viewer viewer(arguments);
28
29    // set up the value with sensible default event handlers.
30    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
31
32    // get details on keyboard and mouse bindings used by the viewer.
33    viewer.getUsage(*arguments.getApplicationUsage());
34
35    // if user request help write it out to cout.
36    if (arguments.read("-h") || arguments.read("--help"))
37    {
38        arguments.getApplicationUsage()->write(std::cout);
39        return 1;
40    }
41
42    // any option left unread are converted into errors to write out later.
43    arguments.reportRemainingOptionsAsUnrecognized();
44
45    // report any errors if they have occured when parsing the program aguments.
46    if (arguments.errors())
47    {
48        arguments.writeErrorMessages(std::cout);
49        return 1;
50    }
51   
52    if (arguments.argc()<=1)
53    {
54        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
55        return 1;
56    }
57
58    // load the nodes from the commandline arguments.
59    osg::Node* loadedModel = osgDB::readNodeFiles(arguments);
60    if (!loadedModel)
61    {
62        return 1;
63    }
64 
65    // to do scribe mode we create a top most group to contain the
66    // original model, and then a second group contains the same model
67    // but overrides various state attributes, so that the second instance
68    // is rendered as wireframe.
69   
70    osg::Group* rootnode = new osg::Group;
71
72    osg::Group* decorator = new osg::Group;
73   
74    rootnode->addChild(loadedModel);
75   
76   
77    rootnode->addChild(decorator);
78   
79    decorator->addChild(loadedModel); 
80
81    // set up the state so that the underlying color is not seen through
82    // and that the drawing mode is changed to wireframe, and a polygon offset
83    // is added to ensure that we see the wireframe itself, and turn off
84    // so texturing too.
85    osg::StateSet* stateset = new osg::StateSet;
86    osg::Material* material = new osg::Material;
87    osg::PolygonOffset* polyoffset = new osg::PolygonOffset;
88    polyoffset->setFactor(-1.0f);
89    polyoffset->setUnits(-1.0f);
90    osg::PolygonMode* polymode = new osg::PolygonMode;
91    polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
92    stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
93    stateset->setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
94    stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
95    stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
96    stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
97   
98//     osg::LineStipple* linestipple = new osg::LineStipple;
99//     linestipple->setFactor(1);
100//     linestipple->setPattern(0xf0f0);
101//     stateset->setAttributeAndModes(linestipple,osg::StateAttribute::OVERRIDE_ON);
102   
103    decorator->setStateSet(stateset);
104 
105   
106    // run optimization over the scene graph
107    osgUtil::Optimizer optimzer;
108    optimzer.optimize(rootnode);
109     
110    // add a viewport to the viewer and attach the scene graph.
111    viewer.setSceneData( rootnode );
112   
113    // create the windows and run the threads.
114    viewer.realize();
115
116    while( !viewer.done() )
117    {
118        // wait for all cull and draw threads to complete.
119        viewer.sync();
120
121        // update the scene by traversing it with the the update visitor which will
122        // call all node update callbacks and animations.
123        viewer.update();
124         
125        // fire off the cull and draw traversals of the scene.
126        viewer.frame();
127       
128    }
129   
130    // wait for all cull and draw threads to complete before exit.
131    viewer.sync();
132
133    return 0;
134}
Note: See TracBrowser for help on using the browser.