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

Revision 1832, 3.6 kB (checked in by robert, 11 years ago)

Changed the Viewer::realize() calls across to not using the threading paramter
leaving it up to the Viewer to specify the mode (which by default is MultiThreaded?).
Added a check for the presence of osgParticle systems so that threading is
disabled in this case.

  • 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.getApplicationName()+" [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    if (arguments.argc()<=1)
55    {
56        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
57        return 1;
58    }
59
60    // load the nodes from the commandline arguments.
61    osg::Node* rootnode = osgDB::readNodeFiles(arguments);
62    if (!rootnode)
63    {
64//        write_usage(osg::notify(osg::NOTICE),argv[0]);
65        return 1;
66    }
67   
68    osg::Image* image = osgDB::readImageFile("Images/reflect.rgb");
69    if (image)
70    {
71        osg::Texture2D* texture = new osg::Texture2D;
72        texture->setImage(image);
73
74        osg::TexGen* texgen = new osg::TexGen;
75        texgen->setMode(osg::TexGen::SPHERE_MAP);
76
77        osg::TexEnv* texenv = new osg::TexEnv;
78        texenv->setMode(osg::TexEnv::BLEND);
79        texenv->setColor(osg::Vec4(0.3f,0.3f,0.3f,0.3f));
80
81        osg::StateSet* stateset = new osg::StateSet;
82        stateset->setTextureAttributeAndModes(1,texture,osg::StateAttribute::ON);
83        stateset->setTextureAttributeAndModes(1,texgen,osg::StateAttribute::ON);
84        stateset->setTextureAttribute(1,texenv);
85       
86        rootnode->setStateSet(stateset);
87    }
88    else
89    {
90        osg::notify(osg::NOTICE)<<"unable to load reflect map, model will not be mutlitextured"<<std::endl;
91    }
92
93    // run optimization over the scene graph
94    osgUtil::Optimizer optimzer;
95    optimzer.optimize(rootnode);
96     
97    // add a viewport to the viewer and attach the scene graph.
98    viewer.setSceneData( rootnode );
99   
100    // create the windows and run the threads.
101    viewer.realize();
102
103    while( !viewer.done() )
104    {
105        // wait for all cull and draw threads to complete.
106        viewer.sync();
107
108        // update the scene by traversing it with the the update visitor which will
109        // call all node update callbacks and animations.
110        viewer.update();
111         
112        // fire off the cull and draw traversals of the scene.
113        viewer.frame();
114       
115    }
116   
117    // wait for all cull and draw threads to complete before exit.
118    viewer.sync();
119
120    return 0;
121}
Note: See TracBrowser for help on using the browser.