root/OpenSceneGraph/trunk/examples/osgimagesequence/osgimagesequence.cpp @ 8660

Revision 8660, 3.9 kB (checked in by robert, 6 years ago)

Added support for pruning old images, recording the Duration in the .osg file, and -o filename output support in osgimagesequence.

Line 
1/* OpenSceneGraph example, osgtexture3D.
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 <osg/Node>
20#include <osg/Geometry>
21#include <osg/Notify>
22#include <osg/Texture1D>
23#include <osg/Texture2D>
24#include <osg/Texture3D>
25#include <osg/TextureRectangle>
26#include <osg/ImageSequence>
27#include <osg/Geode>
28
29#include <osgDB/Registry>
30#include <osgDB/ReadFile>
31#include <osgDB/WriteFile>
32
33#include <osgViewer/Viewer>
34
35#include <iostream>
36
37//
38// A simple demo demonstrating how to set on an animated texture using an osg::ImageSequence
39//
40
41osg::StateSet* createState()
42{
43    osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence;
44
45    imageSequence->setDuration(2.0);
46    imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posx.png"));
47    imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negx.png"));
48    imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posy.png"));
49    imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negy.png"));
50    imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posz.png"));
51    imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negz.png"));
52
53#if 1
54    osg::Texture2D* texture = new osg::Texture2D;
55    texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
56    texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
57    texture->setWrap(osg::Texture::WRAP_R,osg::Texture::REPEAT);
58    texture->setResizeNonPowerOfTwoHint(false);
59    texture->setImage(imageSequence.get());
60    //texture->setTextureSize(512,512);
61   
62    //texture->setUpdateCallback(new osg::ImageSequence::UpdateCallback);
63#else   
64    osg::TextureRectangle* texture = new osg::TextureRectangle;
65    texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
66    texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
67    texture->setWrap(osg::Texture::WRAP_R,osg::Texture::REPEAT);
68    // texture->setResizeNonPowerOfTwoHint(false);
69    texture->setImage(imageSequence.get());
70    //texture->setTextureSize(512,512);
71   
72    //texture->setUpdateCallback(new osg::ImageSequence::UpdateCallback);
73#endif
74
75    // create the StateSet to store the texture data
76    osg::StateSet* stateset = new osg::StateSet;
77
78    stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
79
80    return stateset;
81}
82
83osg::Node* createModel()
84{
85
86    // create the geometry of the model, just a simple 2d quad right now.   
87    osg::Geode* geode = new osg::Geode;
88    geode->addDrawable(osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0), osg::Vec3(1.0f,0.0f,0.0), osg::Vec3(0.0f,0.0f,1.0f)));
89
90    geode->setStateSet(createState());
91   
92    return geode;
93
94}
95
96
97int main(int argc, char **argv)
98{
99    osg::ArgumentParser arguments(&argc,argv);
100
101    // construct the viewer.
102    osgViewer::Viewer viewer(arguments);
103
104    // create a model from the images and pass it to the viewer.
105    viewer.setSceneData(createModel());
106
107    std::string filename;
108    if (arguments.read("-o",filename))
109    {
110        osgDB::writeNodeFile(*viewer.getSceneData(),filename);
111    }
112
113    return viewer.run();
114}
Note: See TracBrowser for help on using the browser.