| 1 | #include <osg/ArgumentParser> |
|---|
| 2 | |
|---|
| 3 | #include <osgProducer/Viewer> |
|---|
| 4 | |
|---|
| 5 | #include <osgShadow/OccluderGeometry> |
|---|
| 6 | |
|---|
| 7 | #include <osgDB/ReadFile> |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | int main(int argc, char** argv) |
|---|
| 11 | { |
|---|
| 12 | |
|---|
| 13 | osg::ArgumentParser arguments(&argc, argv); |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 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 | |
|---|
| 23 | osgProducer::Viewer viewer(arguments); |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | viewer.getUsage(*arguments. getApplicationUsage()); |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 33 | { |
|---|
| 34 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 35 | return 1; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 79 | viewer.realize(); |
|---|
| 80 | |
|---|
| 81 | while (!viewer.done()) |
|---|
| 82 | { |
|---|
| 83 | |
|---|
| 84 | viewer.sync(); |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | viewer.update(); |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | viewer.frame(); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | viewer.sync(); |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | viewer.cleanup_frame(); |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | viewer.sync(); |
|---|
| 102 | |
|---|
| 103 | return 0; |
|---|
| 104 | } |
|---|