- Timestamp:
- 07/21/08 19:28:22 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgimagesequence/osgimagesequence.cpp
r8637 r8642 36 36 // 37 37 38 39 typedef std::vector< osg::ref_ptr<osg::Image> > ImageList; 40 41 42 class MyGraphicsContext { 43 public: 44 MyGraphicsContext() 38 struct ImageUpdateCallback : public osg::StateAttribute::Callback 39 { 40 /** do customized update code.*/ 41 virtual void operator () (osg::StateAttribute* attr, osg::NodeVisitor* nv) 42 { 43 const osg::FrameStamp* fs = nv!=0 ? nv->getFrameStamp() : 0; 44 osg::Texture2D* texture2D = dynamic_cast<osg::Texture2D*>(attr); 45 if (texture2D && texture2D->getImage() && fs) 45 46 { 46 osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; 47 traits->x = 0; 48 traits->y = 0; 49 traits->width = 1; 50 traits->height = 1; 51 traits->windowDecoration = false; 52 traits->doubleBuffer = false; 53 traits->sharedContext = 0; 54 traits->pbuffer = true; 55 56 _gc = osg::GraphicsContext::createGraphicsContext(traits.get()); 57 58 if (!_gc) 59 { 60 traits->pbuffer = false; 61 _gc = osg::GraphicsContext::createGraphicsContext(traits.get()); 62 } 63 64 if (_gc.valid()) 65 { 66 _gc->realize(); 67 _gc->makeCurrent(); 68 } 47 texture2D->getImage()->update(fs); 69 48 } 70 71 bool valid() const { return _gc.valid() && _gc->isRealized(); } 72 73 private: 74 osg::ref_ptr<osg::GraphicsContext> _gc; 49 } 75 50 }; 76 77 51 78 52 osg::StateSet* createState() … … 90 64 imageSequence->addImage(image_3.get(), 0.25); 91 65 92 imageSequence->setImage(image_0->s(),image_0->t(),image_0->r(),93 image_0->getInternalTextureFormat(),94 image_0->getPixelFormat(),image_0->getDataType(),95 image_0->data(),96 osg::Image::NO_DELETE,97 image_0->getPacking());98 99 66 osg::Texture2D* texture = new osg::Texture2D; 100 67 texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); … … 103 70 texture->setResizeNonPowerOfTwoHint(false); 104 71 texture->setImage(imageSequence.get()); 72 //texture->setTextureSize(512,512); 73 74 texture->setUpdateCallback(new ImageUpdateCallback); 105 75 106 76 // create the StateSet to store the texture data 107 77 osg::StateSet* stateset = new osg::StateSet; 78 108 79 stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); 109 80
