root/OpenSceneGraph/trunk/examples/osgmultitexture/osgmultitexture.cpp @ 1697

Revision 1697, 3.4 kB (checked in by robert, 11 years ago)

Ported osgGLUT based src/Demos across to being osgProducer based, and placed
them in the new examples/ directory.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#include <osgProducer/Viewer>
2
3#include <osg/Notify>
4
5#include <osg/Texture2D>
6#include <osg/TexEnv>
7#include <osg/TexGen>
8
9#include <osgDB/Registry>
10#include <osgDB/ReadFile>
11
12#include <osgGA/TrackballManipulator>
13#include <osgGA/FlightManipulator>
14#include <osgGA/DriveManipulator>
15
16#include <osgUtil/Optimizer>
17
18
19int main( int argc, char **argv )
20{
21    // use an ArgumentParser object to manage the program arguments.
22    osg::ArgumentParser arguments(&argc,argv);
23
24    // set up the usage document, in case we need to print out how to use this program.
25    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] filename ...");
26    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
27   
28    // construct the viewer.
29    osgProducer::Viewer viewer(arguments);
30
31    // set up the value with sensible default event handlers.
32    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
33
34    // get details on keyboard and mouse bindings used by the viewer.
35    viewer.getUsage(*arguments.getApplicationUsage());
36
37    // if user request help write it out to cout.
38    if (arguments.read("-h") || arguments.read("--help"))
39    {
40        arguments.getApplicationUsage()->write(std::cout);
41        return 1;
42    }
43
44    // any option left unread are converted into errors to write out later.
45    arguments.reportRemainingOptionsAsUnrecognized();
46
47    // report any errors if they have occured when parsing the program aguments.
48    if (arguments.errors())
49    {
50        arguments.writeErrorMessages(std::cout);
51        return 1;
52    }
53
54    // load the nodes from the commandline arguments.
55    osg::Node* rootnode = osgDB::readNodeFiles(arguments);
56    if (!rootnode)
57    {
58//        write_usage(osg::notify(osg::NOTICE),argv[0]);
59        return 1;
60    }
61   
62    osg::Image* image = osgDB::readImageFile("Images/reflect.rgb");
63    if (image)
64    {
65        osg::Texture2D* texture = new osg::Texture2D;
66        texture->setImage(image);
67
68        osg::TexGen* texgen = new osg::TexGen;
69        texgen->setMode(osg::TexGen::SPHERE_MAP);
70
71        osg::TexEnv* texenv = new osg::TexEnv;
72        texenv->setMode(osg::TexEnv::BLEND);
73        texenv->setColor(osg::Vec4(0.3f,0.3f,0.3f,0.3f));
74
75        osg::StateSet* stateset = new osg::StateSet;
76        stateset->setTextureAttributeAndModes(1,texture,osg::StateAttribute::ON);
77        stateset->setTextureAttributeAndModes(1,texgen,osg::StateAttribute::ON);
78        stateset->setTextureAttribute(1,texenv);
79       
80        rootnode->setStateSet(stateset);
81    }
82    else
83    {
84        osg::notify(osg::NOTICE)<<"unable to load reflect map, model will not be mutlitextured"<<std::endl;
85    }
86
87    // run optimization over the scene graph
88    osgUtil::Optimizer optimzer;
89    optimzer.optimize(rootnode);
90     
91    // add a viewport to the viewer and attach the scene graph.
92    viewer.setSceneData( rootnode );
93   
94    // create the windows and run the threads.
95    viewer.realize(Producer::CameraGroup::ThreadPerCamera);
96
97    while( !viewer.done() )
98    {
99        // wait for all cull and draw threads to complete.
100        viewer.sync();
101
102        // update the scene by traversing it with the the update visitor which will
103        // call all node update callbacks and animations.
104        viewer.update();
105         
106        // fire off the cull and draw traversals of the scene.
107        viewer.frame();
108       
109    }
110
111    return 0;
112}
Note: See TracBrowser for help on using the browser.