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

Revision 5705, 3.0 kB (checked in by robert, 8 years ago)

Added support for handling osg::ShapeDrawable? style drawables in OccluderGeoemtry?.

  • 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   
57    osg::ref_ptr<osg::Geode> geode = new osg::Geode;
58
59    osg::ref_ptr<osgShadow::OccluderGeometry> occluder = new osgShadow::OccluderGeometry;
60    occluder->computeOccluderGeometry(model.get());
61   
62    geode->addDrawable(occluder.get());
63
64    viewer.setSceneData(geode.get());
65
66    // create the windows and run the threads.
67    viewer.realize();
68
69    while (!viewer.done())
70    {
71      // wait for all cull and draw threads to complete.
72      viewer.sync();
73
74      // update the scene by traversing it with the the update visitor which will
75      // call all node update callbacks and animations.
76      viewer.update();
77         
78      // fire off the cull and draw traversals of the scene.
79      viewer.frame();
80    }
81   
82    // wait for all cull and draw threads to complete.
83    viewer.sync();
84
85    // run a clean up frame to delete all OpenGL objects.
86    viewer.cleanup_frame();
87
88    // wait for all the clean up frame to complete.
89    viewer.sync();
90
91    return 0;
92}
Note: See TracBrowser for help on using the browser.