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

Revision 1697, 4.4 kB (checked in by robert, 11 years ago)

Ported osgGLUT based src/Demos across to being osgProducer based, and placed
them in the new examples/ directory.

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