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

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

Further work on osg::ImageSequence?/osgDB::ImagePager?

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/Texture2D>
23#include <osg/ImageSequence>
24#include <osg/Geode>
25
26#include <osgDB/Registry>
27#include <osgDB/ReadFile>
28
29#include <osgViewer/Viewer>
30
31#include <iostream>
32
33//
34// A simple demo demonstrating how to set on an animated texture using an osg::ImageSequence
35//
36
37osg::StateSet* createState()
38{
39    // read 4 2d images
40    osg::ref_ptr<osg::Image> image_0 = osgDB::readImageFile("Images/lz.rgb");
41    osg::ref_ptr<osg::Image> image_1 = osgDB::readImageFile("Images/reflect.rgb");
42    osg::ref_ptr<osg::Image> image_2 = osgDB::readImageFile("Images/tank.rgb");
43    osg::ref_ptr<osg::Image> image_3 = osgDB::readImageFile("Images/skymap.jpg");
44
45    osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence;
46    imageSequence->addImage(image_0.get());
47    imageSequence->addImage(image_1.get());
48    imageSequence->addImage(image_2.get());
49    imageSequence->addImage(image_3.get());
50   
51    osg::Texture2D* texture = new osg::Texture2D;
52    texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
53    texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
54    texture->setWrap(osg::Texture2D::WRAP_R,osg::Texture2D::REPEAT);
55    texture->setResizeNonPowerOfTwoHint(false);
56    texture->setImage(imageSequence.get());
57    //texture->setTextureSize(512,512);
58   
59    texture->setUpdateCallback(new osg::ImageSequence::UpdateCallback);
60
61    // create the StateSet to store the texture data
62    osg::StateSet* stateset = new osg::StateSet;
63
64    stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
65
66    return stateset;
67}
68
69osg::Node* createModel()
70{
71
72    // create the geometry of the model, just a simple 2d quad right now.   
73    osg::Geode* geode = new osg::Geode;
74    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)));
75
76    geode->setStateSet(createState());
77   
78    return geode;
79
80}
81
82
83int main(int , char **)
84{
85    // construct the viewer.
86    osgViewer::Viewer viewer;
87
88    // create a model from the images and pass it to the viewer.
89    viewer.setSceneData(createModel());
90
91    return viewer.run();
92}
Note: See TracBrowser for help on using the browser.