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

Revision 5954, 3.6 kB (checked in by robert, 8 years ago)

Ported following examples to osgViewer:

osgparticleeffects
osgphotoalbum
osgpick
osgpoints
osgpointsprite
osgprecipitation
osgprerender
osgprerendercubemap
osgreflect
osgscalarbar
osgscribe
osgsequence
osgplanets

  • 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 <osgViewer/Viewer>
13
14#include <osgUtil/Optimizer>
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    // construct the viewer.
22    osgViewer::Viewer viewer;
23
24    // load the nodes from the commandline arguments.
25    osg::Node* loadedModel = osgDB::readNodeFiles(arguments);
26    if (!loadedModel)
27    {
28        osg::notify(osg::NOTICE)<<"Please specifiy a model filename on the command line."<<std::endl;
29        return 1;
30    }
31 
32    // to do scribe mode we create a top most group to contain the
33    // original model, and then a second group contains the same model
34    // but overrides various state attributes, so that the second instance
35    // is rendered as wireframe.
36   
37    osg::Group* rootnode = new osg::Group;
38
39    osg::Group* decorator = new osg::Group;
40   
41    rootnode->addChild(loadedModel);
42   
43   
44    rootnode->addChild(decorator);
45   
46    decorator->addChild(loadedModel); 
47
48    // set up the state so that the underlying color is not seen through
49    // and that the drawing mode is changed to wireframe, and a polygon offset
50    // is added to ensure that we see the wireframe itself, and turn off
51    // so texturing too.
52    osg::StateSet* stateset = new osg::StateSet;
53    osg::PolygonOffset* polyoffset = new osg::PolygonOffset;
54    polyoffset->setFactor(-1.0f);
55    polyoffset->setUnits(-1.0f);
56    osg::PolygonMode* polymode = new osg::PolygonMode;
57    polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
58    stateset->setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
59    stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
60
61#if 1
62    osg::Material* material = new osg::Material;
63    stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
64    stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
65#else
66    // version which sets the color of the wireframe.
67    osg::Material* material = new osg::Material;
68    material->setColorMode(osg::Material::OFF); // switch glColor usage off
69    // turn all lighting off
70    material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f));
71    material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f));
72    material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f));
73    // except emission... in which we set the color we desire
74    material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,1.0f,0.0f,1.0f));
75    stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
76    stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
77#endif
78
79    stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
80   
81//     osg::LineStipple* linestipple = new osg::LineStipple;
82//     linestipple->setFactor(1);
83//     linestipple->setPattern(0xf0f0);
84//     stateset->setAttributeAndModes(linestipple,osg::StateAttribute::OVERRIDE_ON);
85   
86    decorator->setStateSet(stateset);
87 
88   
89    // run optimization over the scene graph
90    osgUtil::Optimizer optimzer;
91    optimzer.optimize(rootnode);
92     
93    // add a viewport to the viewer and attach the scene graph.
94    viewer.setSceneData( rootnode );
95   
96    return viewer.run();
97}
Note: See TracBrowser for help on using the browser.