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

Revision 5927, 2.5 kB (checked in by robert, 7 years ago)

Ported following examples to osgViewer:

osggeodemo
osggeometry
osghud
osgimpostor
osgkeyboard
osglauncher
osglight
osglightpoint
osglogicop
osglogo
osgmovie
osgmultiplecameras
osgmultitexture
osgoccluder
osgparametric
osgparticle

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#include <osgViewer/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#include <iostream>
19
20int main( int argc, char **argv )
21{
22    // use an ArgumentParser object to manage the program arguments.
23    osg::ArgumentParser arguments(&argc,argv);
24   
25    // construct the viewer.
26    osgViewer::Viewer viewer;
27
28    // load the nodes from the commandline arguments.
29    osg::Node* rootnode = osgDB::readNodeFiles(arguments);
30    if (!rootnode)
31    {
32        osg::notify(osg::NOTICE)<<"Please specify and model filename on the command line."<<std::endl;
33        return 1;
34    }
35   
36    osg::Image* image = osgDB::readImageFile("Images/reflect.rgb");
37    if (image)
38    {
39        osg::Texture2D* texture = new osg::Texture2D;
40        texture->setImage(image);
41
42        osg::TexGen* texgen = new osg::TexGen;
43        texgen->setMode(osg::TexGen::SPHERE_MAP);
44
45        osg::TexEnv* texenv = new osg::TexEnv;
46        texenv->setMode(osg::TexEnv::BLEND);
47        texenv->setColor(osg::Vec4(0.3f,0.3f,0.3f,0.3f));
48
49        osg::StateSet* stateset = new osg::StateSet;
50        stateset->setTextureAttributeAndModes(1,texture,osg::StateAttribute::ON);
51        stateset->setTextureAttributeAndModes(1,texgen,osg::StateAttribute::ON);
52        stateset->setTextureAttribute(1,texenv);
53       
54        rootnode->setStateSet(stateset);
55    }
56    else
57    {
58        osg::notify(osg::NOTICE)<<"unable to load reflect map, model will not be mutlitextured"<<std::endl;
59    }
60
61    // run optimization over the scene graph
62    osgUtil::Optimizer optimzer;
63    optimzer.optimize(rootnode);
64     
65    // add a viewport to the viewer and attach the scene graph.
66    viewer.setSceneData( rootnode );
67   
68    // create the windows and run the threads.
69    viewer.realize();
70
71    for(unsigned int contextID = 0;
72        contextID<osg::DisplaySettings::instance()->getMaxNumberOfGraphicsContexts();
73        ++contextID)
74    {
75        osg::Texture::Extensions* textExt = osg::Texture::getExtensions(contextID,false);
76        if (textExt)
77        {
78            if (!textExt->isMultiTexturingSupported())
79            {
80                std::cout<<"Warning: multi-texturing not supported by OpenGL drivers, unable to run application."<<std::endl;
81                return 1;
82            }
83        }
84    }
85
86    return viewer.run();
87}
Note: See TracBrowser for help on using the browser.