| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 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 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | osg::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 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 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 | |
|---|
| 69 | texture->setImage(imageSequence.get()); |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | #endif |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | osg::StateSet* stateset = new osg::StateSet; |
|---|
| 77 | |
|---|
| 78 | stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); |
|---|
| 79 | |
|---|
| 80 | return stateset; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | osg::Node* createModel() |
|---|
| 84 | { |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 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 | |
|---|
| 97 | int main(int argc, char **argv) |
|---|
| 98 | { |
|---|
| 99 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | osgViewer::Viewer viewer(arguments); |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 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 | } |
|---|