root/OpenSceneGraph/trunk/examples/osgshadow/osgshadow.cpp @ 5746

Revision 5746, 3.5 kB (checked in by robert, 7 years ago)

First cut at generating the ShadowVolumeGeometry?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#include <osg/ArgumentParser>
2
3#include <osgProducer/Viewer>
4
5#include <osgShadow/OccluderGeometry>
6
7#include <osgDB/ReadFile>
8
9
10int main(int argc, char** argv)
11{
12    // use an ArgumentParser object to manage the program arguments.
13    osg::ArgumentParser arguments(&argc, argv);
14
15    // set up the usage document, in case we need to print out how to use this program.
16    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName() + " is the example which demonstrates using of GL_ARB_shadow extension implemented in osg::Texture class");
17    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName());
18    arguments.getApplicationUsage()->addCommandLineOption("-h or --help", "Display this information");
19    arguments.getApplicationUsage()->addCommandLineOption("--with-base-texture", "Adde base texture to shadowed model.");
20    arguments.getApplicationUsage()->addCommandLineOption("--no-base-texture", "Adde base texture to shadowed model.");
21
22    // construct the viewer.
23    osgProducer::Viewer viewer(arguments);
24
25    // set up the value with sensible default event handlers.
26    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
27
28    // get details on keyboard and mouse bindings used by the viewer.
29    viewer.getUsage(*arguments. getApplicationUsage());
30
31    // if user request help write it out to cout.
32    if (arguments.read("-h") || arguments.read("--help"))
33    {
34        arguments.getApplicationUsage()->write(std::cout);
35        return 1;
36    }
37
38    // any option left unread are converted into errors to write out later.
39    arguments.reportRemainingOptionsAsUnrecognized();
40
41    // report any errors if they have occured when parsing the program aguments.
42    if (arguments.errors())
43    {
44      arguments.writeErrorMessages(std::cout);
45      return 1;
46    }
47
48
49    osg::ref_ptr<osg::Node> model = osgDB::readNodeFiles(arguments);
50    if (!model)
51    {
52        osg::notify(osg::NOTICE)<<"No model loaded, please specify a model to load."<<std::endl;
53        return 1;
54    }
55   
56    const osg::BoundingSphere& bs = model->getBound();
57    osg::Plane basePlane(0.0, 0.0, 1.0, -( bs.center().z() - bs.radius() ) );
58   
59    osg::ref_ptr<osg::Geode> geode = new osg::Geode;
60
61    osg::ref_ptr<osgShadow::OccluderGeometry> occluder = new osgShadow::OccluderGeometry;
62    occluder->computeOccluderGeometry(model.get());
63    occluder->getBoundingPolytope().add(basePlane);
64    //geode->addDrawable(occluder.get());
65   
66    osg::ref_ptr<osgShadow::ShadowVolumeGeometry> shadowVolume = new osgShadow::ShadowVolumeGeometry;
67    occluder->comptueShadowVolumeGeometry(osg::Vec4(0.0f,-.5f,-1.0f,0.0f), *shadowVolume);
68    geode->addDrawable(shadowVolume.get());
69
70
71    osg::ref_ptr<osg::Group> group = new osg::Group;
72    group->addChild(model.get());
73    group->addChild(geode.get());
74
75
76    viewer.setSceneData(group.get());
77
78    // create the windows and run the threads.
79    viewer.realize();
80
81    while (!viewer.done())
82    {
83      // wait for all cull and draw threads to complete.
84      viewer.sync();
85
86      // update the scene by traversing it with the the update visitor which will
87      // call all node update callbacks and animations.
88      viewer.update();
89         
90      // fire off the cull and draw traversals of the scene.
91      viewer.frame();
92    }
93   
94    // wait for all cull and draw threads to complete.
95    viewer.sync();
96
97    // run a clean up frame to delete all OpenGL objects.
98    viewer.cleanup_frame();
99
100    // wait for all the clean up frame to complete.
101    viewer.sync();
102
103    return 0;
104}
Note: See TracBrowser for help on using the browser.