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

Revision 1844, 4.7 kB (checked in by robert, 12 years ago)

Added desciptions to all the demos.

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