[osg-users] change texture

Tran Thanh Hiep hiep45t2003 at yahoo.com
Mon Oct 29 03:21:17 PDT 2007


and here is image when i run my program :
http://blog.360.yahoo.com/blog-Rs6nWTU5cqM642o5YzZ2Mf_I0w--?cq=1


----- Original Message ----
From: Tran Thanh Hiep <hiep45t2003 at yahoo.com>
To: osg-users at lists.openscenegraph.org
Sent: Monday, October 29, 2007 5:17:35 PM
Subject: [osg-users] change texture


hi all, 
in my program i want change a new texture for my model but when i apply a new texture it don't display correct
follow here my code 
   virtual void apply(osg::Geode& node) 
     { 
         int count=node.getNumDrawables();
        for(int i=0;i<count;i++)
        {
            osg::Drawable *pDrawable=node.getDrawable(i);
            osg::Geometry *pGeo=dynamic_cast<osg::Geometry*>(pDrawable);
            osg::StateSet *pStateSet=pGeo->getStateSet();
   
         if(pStateSet!=NULL)
            {
                //pStateSet->getAttributeList();
                osg::Texture2D *txtOldTexture=static_cast<osg::Texture2D*>(pStateSet->getTextureAttribute(0,osg::StateAttribute::Type::TEXTURE));
                //osg::StateAttribute *pStateAttribute=pStateSet->getTextureAttribute(0,osg::StateAttribute::Type::TEXTURE);
                //if(pStateAttribute!=NULL)
                if(txtOldTexture!=NULL)
                {

   
             //     txtOldTexture->flushDeletedTextureObjects(0,0,0.0);
                    // txtOldTexture->setUnRefImageDataAfterApply(false);
                    txtOldTexture->dirtyTextureObject();
                     
                    txtOldTexture->flushAllDeletedTextureObjects(0);
                    // osg::Texture2D *txtOld=dynamic_cast<osg::Texture2D*>(pStateAttribute);
                   
 osg::Image *imgTexture=osgDB::readImageFile(strNameImageFile);
                    //txtOldTexture->areAllTextureObjectsLoaded();
                    txtOldTexture->setImage(0,imgTexture);
                       //txtOld->setImage(imgTexture);
                    bolIsState=true;
                }
            }
        }
please help me 
thanks! 



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam
 protection around 
http://mail.yahoo.com 




__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20071029/89a90510/attachment-0003.htm>


More information about the osg-users mailing list