| 1 | |
|---|
| 2 | |
|---|
| 3 | #include <osgProducer/Viewer> |
|---|
| 4 | |
|---|
| 5 | #include <osgDB/ReadFile> |
|---|
| 6 | |
|---|
| 7 | #include <osg/Geode> |
|---|
| 8 | #include <osg/Geometry> |
|---|
| 9 | #include <osg/StateSet> |
|---|
| 10 | #include <osg/Material> |
|---|
| 11 | #include <osg/Texture2D> |
|---|
| 12 | #include <osg/TextureRectangle> |
|---|
| 13 | #include <osg/TexMat> |
|---|
| 14 | #include <osg/CullFace> |
|---|
| 15 | |
|---|
| 16 | #include <osgGA/TrackballManipulator> |
|---|
| 17 | |
|---|
| 18 | osg::Geometry* createTexturedQuadGeometry(const osg::Vec3& pos,float width,float height, osg::Image* image) |
|---|
| 19 | { |
|---|
| 20 | bool useTextureRectangle = true; |
|---|
| 21 | if (useTextureRectangle) |
|---|
| 22 | { |
|---|
| 23 | osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(pos, |
|---|
| 24 | osg::Vec3(width,0.0f,0.0f), |
|---|
| 25 | osg::Vec3(0.0f,0.0f,height), |
|---|
| 26 | image->s(),image->t()); |
|---|
| 27 | |
|---|
| 28 | pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0, |
|---|
| 29 | new osg::TextureRectangle(image), |
|---|
| 30 | osg::StateAttribute::ON); |
|---|
| 31 | |
|---|
| 32 | return pictureQuad; |
|---|
| 33 | } |
|---|
| 34 | else |
|---|
| 35 | { |
|---|
| 36 | osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(pos, |
|---|
| 37 | osg::Vec3(width,0.0f,0.0f), |
|---|
| 38 | osg::Vec3(0.0f,0.0f,height), |
|---|
| 39 | 1.0f,1.0f); |
|---|
| 40 | |
|---|
| 41 | pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0, |
|---|
| 42 | new osg::Texture2D(image), |
|---|
| 43 | osg::StateAttribute::ON); |
|---|
| 44 | |
|---|
| 45 | return pictureQuad; |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | int main(int argc, char** argv) |
|---|
| 50 | { |
|---|
| 51 | |
|---|
| 52 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); |
|---|
| 56 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); |
|---|
| 57 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
|---|
| 58 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | osgProducer::Viewer viewer(arguments); |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 72 | { |
|---|
| 73 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 74 | return 1; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | osg::Geode* geode = new osg::Geode; |
|---|
| 78 | osg::Vec3 pos(0.0f,0.0f,0.0f); |
|---|
| 79 | |
|---|
| 80 | for(int i=1;i<arguments.argc();++i) |
|---|
| 81 | { |
|---|
| 82 | if (arguments.isString(i)) |
|---|
| 83 | { |
|---|
| 84 | osg::Image* image = osgDB::readImageFile(arguments[i]); |
|---|
| 85 | geode->addDrawable(createTexturedQuadGeometry(pos,image->s(),image->t(),image)); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | if (arguments.errors()) |
|---|
| 93 | { |
|---|
| 94 | arguments.writeErrorMessages(std::cout); |
|---|
| 95 | return 1; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | if (arguments.argc()<=1) |
|---|
| 99 | { |
|---|
| 100 | arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); |
|---|
| 101 | return 1; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | if (arguments.errors()) |
|---|
| 110 | { |
|---|
| 111 | arguments.writeErrorMessages(std::cout); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | viewer.setSceneData(geode); |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | viewer.realize(); |
|---|
| 119 | |
|---|
| 120 | while( !viewer.done() ) |
|---|
| 121 | { |
|---|
| 122 | |
|---|
| 123 | viewer.sync(); |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | viewer.update(); |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | viewer.frame(); |
|---|
| 131 | |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | viewer.sync(); |
|---|
| 136 | |
|---|
| 137 | return 0; |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | } |
|---|