root/OpenSceneGraph/trunk/examples/osgmovie/osgmovie.cpp @ 2809

Revision 2809, 4.4 kB (checked in by robert, 10 years ago)

Cleaned up osgmovie example so it no longer depends upon LibMpeg?3, just
using readImageFile instead.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1// -*-c++-*-
2
3#include <osgProducer/Viewer>
4
5#include <osgDB/ReadFile>
6
7#include <osg/Geode>
8#include <osg/Geometry>
9#include <osg/StateSet>
10#include <osg/Material>
11#include <osg/Texture2D>
12#include <osg/TextureRectangle>
13#include <osg/TexMat>
14#include <osg/CullFace>
15
16#include <osgGA/TrackballManipulator>
17
18osg::Geometry* createTexturedQuadGeometry(const osg::Vec3& pos,float width,float height, osg::Image* image)
19{
20    bool useTextureRectangle = true;
21    if (useTextureRectangle)
22    {
23        osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(pos,
24                                           osg::Vec3(width,0.0f,0.0f),
25                                           osg::Vec3(0.0f,0.0f,height),
26                                           image->s(),image->t());
27                                       
28        pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0,
29                    new osg::TextureRectangle(image),
30                    osg::StateAttribute::ON);
31                   
32        return pictureQuad;
33    }
34    else
35    {
36        osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(pos,
37                                           osg::Vec3(width,0.0f,0.0f),
38                                           osg::Vec3(0.0f,0.0f,height),
39                                           1.0f,1.0f);
40                                       
41        pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0,
42                    new osg::Texture2D(image),
43                    osg::StateAttribute::ON);
44
45        return pictureQuad;
46    }
47}
48
49int main(int argc, char** argv)
50{
51    // use an ArgumentParser object to manage the program arguments.
52    osg::ArgumentParser arguments(&argc,argv);
53   
54    // set up the usage document, in case we need to print out how to use this program.
55    arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
56    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models.");
57    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
58    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
59   
60
61    // construct the viewer.
62    osgProducer::Viewer viewer(arguments);
63
64    // set up the value with sensible default event handlers.
65    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
66
67    // get details on keyboard and mouse bindings used by the viewer.
68    viewer.getUsage(*arguments.getApplicationUsage());
69
70    // if user request help write it out to cout.
71    if (arguments.read("-h") || arguments.read("--help"))
72    {
73        arguments.getApplicationUsage()->write(std::cout);
74        return 1;
75    }
76
77    osg::Geode* geode = new osg::Geode;
78    osg::Vec3 pos(0.0f,0.0f,0.0f);
79   
80    for(int i=1;i<arguments.argc();++i)
81    {
82        if (arguments.isString(i))
83        {
84            osg::Image* image = osgDB::readImageFile(arguments[i]);
85            geode->addDrawable(createTexturedQuadGeometry(pos,image->s(),image->t(),image));
86        }
87
88    }
89
90
91    // report any errors if they have occured when parsing the program aguments.
92    if (arguments.errors())
93    {
94        arguments.writeErrorMessages(std::cout);
95        return 1;
96    }
97   
98    if (arguments.argc()<=1)
99    {
100        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
101        return 1;
102    }
103
104
105    // any option left unread are converted into errors to write out later.
106    arguments.reportRemainingOptionsAsUnrecognized();
107
108    // report any errors if they have occured when parsing the program aguments.
109    if (arguments.errors())
110    {
111        arguments.writeErrorMessages(std::cout);
112    }
113
114    // set the scene to render
115    viewer.setSceneData(geode);
116
117    // create the windows and run the threads.
118    viewer.realize();
119
120    while( !viewer.done() )
121    {
122        // wait for all cull and draw threads to complete.
123        viewer.sync();
124       
125        // update the scene by traversing it with the the update visitor which will
126        // call all node update callbacks and animations.
127        viewer.update();
128         
129        // fire off the cull and draw traversals of the scene.
130        viewer.frame();
131       
132    }
133   
134    // wait for all cull and draw threads to complete before exit.
135    viewer.sync();
136
137    return 0;
138
139
140}
Note: See TracBrowser for help on using the browser.