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

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

Further work on osgShadow::GeometryOccluder?

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