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

Revision 1747, 4.3 kB (checked in by robert, 12 years ago)

Added a viewer.sync to the end of all the demos.

Removed the Win32 remapping of keycodes from the osgProducer::EventAdapter?.

  • 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.getProgramName()+" [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    // load the nodes from the commandline arguments.
53    osg::Node* loadedModel = osgDB::readNodeFiles(arguments);
54    if (!loadedModel)
55    {
56        return 1;
57    }
58 
59    // to do scribe mode we create a top most group to contain the
60    // original model, and then a second group contains the same model
61    // but overrides various state attributes, so that the second instance
62    // is rendered as wireframe.
63   
64    osg::Group* rootnode = new osg::Group;
65
66    osg::Group* decorator = new osg::Group;
67   
68    rootnode->addChild(loadedModel);
69   
70   
71    rootnode->addChild(decorator);
72   
73    decorator->addChild(loadedModel); 
74
75    // set up the state so that the underlying color is not seen through
76    // and that the drawing mode is changed to wireframe, and a polygon offset
77    // is added to ensure that we see the wireframe itself, and turn off
78    // so texturing too.
79    osg::StateSet* stateset = new osg::StateSet;
80    osg::Material* material = new osg::Material;
81    osg::PolygonOffset* polyoffset = new osg::PolygonOffset;
82    polyoffset->setFactor(-1.0f);
83    polyoffset->setUnits(-1.0f);
84    osg::PolygonMode* polymode = new osg::PolygonMode;
85    polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
86    stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
87    stateset->setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
88    stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
89    stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
90    stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
91   
92//     osg::LineStipple* linestipple = new osg::LineStipple;
93//     linestipple->setFactor(1);
94//     linestipple->setPattern(0xf0f0);
95//     stateset->setAttributeAndModes(linestipple,osg::StateAttribute::OVERRIDE_ON);
96   
97    decorator->setStateSet(stateset);
98 
99   
100    // run optimization over the scene graph
101    osgUtil::Optimizer optimzer;
102    optimzer.optimize(rootnode);
103     
104    // add a viewport to the viewer and attach the scene graph.
105    viewer.setSceneData( rootnode );
106   
107    // create the windows and run the threads.
108    viewer.realize(Producer::CameraGroup::ThreadPerCamera);
109
110    while( !viewer.done() )
111    {
112        // wait for all cull and draw threads to complete.
113        viewer.sync();
114
115        // update the scene by traversing it with the the update visitor which will
116        // call all node update callbacks and animations.
117        viewer.update();
118         
119        // fire off the cull and draw traversals of the scene.
120        viewer.frame();
121       
122    }
123   
124    // wait for all cull and draw threads to complete before exit.
125    viewer.sync();
126
127    return 0;
128}
Note: See TracBrowser for help on using the browser.