| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #include <osgViewer/Viewer> |
|---|
| 20 | |
|---|
| 21 | #include <osg/Notify> |
|---|
| 22 | |
|---|
| 23 | #include <osg/Texture2D> |
|---|
| 24 | #include <osg/TexEnv> |
|---|
| 25 | #include <osg/TexGen> |
|---|
| 26 | |
|---|
| 27 | #include <osgDB/Registry> |
|---|
| 28 | #include <osgDB/ReadFile> |
|---|
| 29 | |
|---|
| 30 | #include <osgGA/TrackballManipulator> |
|---|
| 31 | #include <osgGA/FlightManipulator> |
|---|
| 32 | #include <osgGA/DriveManipulator> |
|---|
| 33 | |
|---|
| 34 | #include <osgUtil/Optimizer> |
|---|
| 35 | |
|---|
| 36 | #include <iostream> |
|---|
| 37 | |
|---|
| 38 | int main( int argc, char **argv ) |
|---|
| 39 | { |
|---|
| 40 | |
|---|
| 41 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | osgViewer::Viewer viewer; |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | osg::Node* rootnode = osgDB::readNodeFiles(arguments); |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | if (!rootnode) rootnode = osgDB::readNodeFile("cessnafire.osg"); |
|---|
| 51 | |
|---|
| 52 | if (!rootnode) |
|---|
| 53 | { |
|---|
| 54 | osg::notify(osg::NOTICE)<<"Please specify and model filename on the command line."<<std::endl; |
|---|
| 55 | return 1; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | osg::Image* image = osgDB::readImageFile("Images/reflect.rgb"); |
|---|
| 59 | if (image) |
|---|
| 60 | { |
|---|
| 61 | osg::Texture2D* texture = new osg::Texture2D; |
|---|
| 62 | texture->setImage(image); |
|---|
| 63 | |
|---|
| 64 | osg::TexGen* texgen = new osg::TexGen; |
|---|
| 65 | texgen->setMode(osg::TexGen::SPHERE_MAP); |
|---|
| 66 | |
|---|
| 67 | osg::TexEnv* texenv = new osg::TexEnv; |
|---|
| 68 | texenv->setMode(osg::TexEnv::BLEND); |
|---|
| 69 | texenv->setColor(osg::Vec4(0.3f,0.3f,0.3f,0.3f)); |
|---|
| 70 | |
|---|
| 71 | osg::StateSet* stateset = new osg::StateSet; |
|---|
| 72 | stateset->setTextureAttributeAndModes(1,texture,osg::StateAttribute::ON); |
|---|
| 73 | stateset->setTextureAttributeAndModes(1,texgen,osg::StateAttribute::ON); |
|---|
| 74 | stateset->setTextureAttribute(1,texenv); |
|---|
| 75 | |
|---|
| 76 | rootnode->setStateSet(stateset); |
|---|
| 77 | } |
|---|
| 78 | else |
|---|
| 79 | { |
|---|
| 80 | osg::notify(osg::NOTICE)<<"unable to load reflect map, model will not be mutlitextured"<<std::endl; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | osgUtil::Optimizer optimzer; |
|---|
| 85 | optimzer.optimize(rootnode); |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | viewer.setSceneData( rootnode ); |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | viewer.realize(); |
|---|
| 92 | |
|---|
| 93 | for(unsigned int contextID = 0; |
|---|
| 94 | contextID<osg::DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(); |
|---|
| 95 | ++contextID) |
|---|
| 96 | { |
|---|
| 97 | osg::Texture::Extensions* textExt = osg::Texture::getExtensions(contextID,false); |
|---|
| 98 | if (textExt) |
|---|
| 99 | { |
|---|
| 100 | if (!textExt->isMultiTexturingSupported()) |
|---|
| 101 | { |
|---|
| 102 | std::cout<<"Warning: multi-texturing not supported by OpenGL drivers, unable to run application."<<std::endl; |
|---|
| 103 | return 1; |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | return viewer.run(); |
|---|
| 109 | } |
|---|