Skip to content

Instantly share code, notes, and snippets.

@gwaldron
Last active October 26, 2021 11:54
Show Gist options
  • Save gwaldron/b04fc956a6efba047267c69ed914a1e0 to your computer and use it in GitHub Desktop.
Save gwaldron/b04fc956a6efba047267c69ed914a1e0 to your computer and use it in GitHub Desktop.
ImageSequence example
#include <osgViewer/Viewer>
#include <osgEarth/Notify>
#include <osgEarth/EarthManipulator>
#include <osgEarth/MapNode>
#include <osg/ImageSequence>
#include <osgDB/ReadFile>
#include <osgEarth/ImageLayer>
using namespace osgEarth;
using namespace osgEarth::Util;
class SequenceLayer : public ImageLayer
{
public:
struct Options : public ImageLayer::Options {
META_LayerOptions(osgEarth, Options, ImageLayer::Options);
//virtual Config getConfig() const { return ImageLayer::Options::getConfig(); }
private:
void fromConfig(const Config&) { }
};
META_Layer(osgEarth, SequenceLayer, Options, ImageLayer, SequenceLayer);
void init() override {
ImageLayer::init();
_image1 = osgDB::readRefImageFile("../data/icon.png");
_image2 = osgDB::readRefImageFile("../data/placemark32.png");
setProfile(Profile::create(Profile::GLOBAL_GEODETIC));
setAsyncLoading(true);
}
GeoImage createImageImplementation(const TileKey& key, ProgressCallback* c) const override {
osg::ImageSequence* seq = new osg::ImageSequence();
seq->addImage(_image1);
seq->addImage(_image2);
seq->setLoopingMode(seq->LOOPING);
seq->setLength(2.0);
seq->play();
return GeoImage(seq, key.getExtent());
}
osg::ref_ptr<osg::Image> _image1, _image2;
};
int
main(int argc, char** argv)
{
osgEarth::initialize();
osg::ArgumentParser arguments(&argc,argv);
osgViewer::Viewer viewer(arguments);
viewer.setCameraManipulator( new EarthManipulator(arguments) );
osg::ref_ptr<Map> map = new Map();
map->addLayer(new SequenceLayer());
auto mapNode = new MapNode(map.get());
viewer.setSceneData( mapNode );
return viewer.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment