root/OpenSceneGraph/trunk/examples/osgmultitexturecontrol/osgmultitexturecontrol.cpp @ 7902

Revision 7902, 3.1 kB (checked in by robert, 6 years ago)

Added beginings of new osgmultitexturecontrol example

Line 
1/* OpenSceneGraph example, osgmultitexture.
2*
3*  Permission is hereby granted, free of charge, to any person obtaining a copy
4*  of this software and associated documentation files (the "Software"), to deal
5*  in the Software without restriction, including without limitation the rights
6*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*  copies of the Software, and to permit persons to whom the Software is
8*  furnished to do so, subject to the following conditions:
9*
10*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
16*  THE SOFTWARE.
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 <osgFX/MultiTextureControl>
31
32#include <osgGA/TerrainManipulator>
33
34#include <osgUtil/Optimizer>
35
36#include <iostream>
37
38template<class T>
39class FindTopMostNodeOfTypeVisitor : public osg::NodeVisitor
40{
41public:
42    FindTopMostNodeOfTypeVisitor():
43        osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
44        _foundNode(0)
45    {}
46   
47    void apply(osg::Node& node)
48    {
49        T* result = dynamic_cast<T*>(&node);
50        if (result)
51        {
52            _foundNode = result;
53        }
54        else
55        {
56            traverse(node);
57        }
58    }
59   
60    T* _foundNode;
61};
62
63template<class T>
64T* findTopMostNodeOfType(osg::Node* node)
65{
66    if (!node) return 0;
67
68    FindTopMostNodeOfTypeVisitor<T> fnotv;
69    node->accept(fnotv);
70   
71    return fnotv._foundNode;
72}
73
74int main( int argc, char **argv )
75{
76    // use an ArgumentParser object to manage the program arguments.
77    osg::ArgumentParser arguments(&argc,argv);
78   
79    // construct the viewer.
80    osgViewer::Viewer viewer;
81
82    // load the nodes from the commandline arguments.
83    osg::Node* rootnode = osgDB::readNodeFiles(arguments);
84
85    if (!rootnode)
86    {
87        osg::notify(osg::NOTICE)<<"Warning: no valid data loaded, please specify a database on the command line."<<std::endl;
88        return 1;
89    }
90   
91    osg::CoordinateSystemNode* csn = findTopMostNodeOfType<osg::CoordinateSystemNode>(rootnode);
92    if (csn)
93    {
94        osg::notify(osg::NOTICE)<<"Found CSN"<<csn<<std::endl;
95    }
96
97    osgFX::MultiTextureControl* mtc = findTopMostNodeOfType<osgFX::MultiTextureControl>(rootnode);
98    if (mtc)
99    {
100        osg::notify(osg::NOTICE)<<"Found MTC "<<mtc<<std::endl;
101    }
102
103    // add terrain manipulator
104    viewer.setCameraManipulator(new osgGA::TerrainManipulator);
105     
106    // add a viewport to the viewer and attach the scene graph.
107    viewer.setSceneData( rootnode );
108   
109    // create the windows and run the threads.
110    viewer.realize();
111
112    return viewer.run();
113}
Note: See TracBrowser for help on using the browser.