|
原ive自带图
贴图后的效果
如何改 才能让图片正常拉伸贴满整个弧面呢?
代码如下
- osg::ref_ptr<osg::Image> image = osgDB::readImageFile(EncodeToUTF8(gif_filepath.c_str()));
- osg::ref_ptr<osg::ImageStream> gif_stream = dynamic_cast<osg::ImageStream *>(image.get());
- osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
- gif_stream->play();
- texture->setImage( gif_stream.get() );
- texture->setResizeNonPowerOfTwoHint( false );
- osg::ref_ptr<osg::Drawable> quad = osg::createTexturedQuadGeometry(
- osg::Vec3(), osg::Vec3f(280.0f, 0.0f, 0.0f), osg::Vec3f(0.0f, 217.0f, 0.0f), 0.0f, 1.0f, 1.0f, 0.0f );
- quad->getOrCreateStateSet()->setTextureAttributeAndModes( 0, texture.get() );
- //设置自动生成坐标
- osg::ref_ptr<osg::TexGen> texgen=new osg::TexGen;
- texgen->setMode(osg::TexGen::SPHERE_MAP);
- //设置纹理环境
- osg::ref_ptr<osg::TexEnv> texenv=new osg::TexEnv;
- texenv->setMode(osg::TexEnv::REPLACE);//替换物体贴图
- //设置blend操作颜色
- texenv->setColor(osg::Vec4(0.6,0.6,0.6,0.0));
- //启用单元一自动生成纹理坐标,并使用纹理
- osg::ref_ptr<osg::StateSet> stateset=new osg::StateSet;
- stateset->setTextureAttributeAndModes(1,texture.get(),osg::StateAttribute::ON);
- stateset->setTextureAttributeAndModes(1,texgen.get(),osg::StateAttribute::ON);
- //设置纹理环境
- stateset->setTextureAttribute(1,texenv.get());
- //设置物体状态
- Camberbedsurfacenode->setStateSet(stateset.get());
复制代码 |
|