方法一:没有几何体,直接显示图片(见王锐、钱学雷的《OSG三维渲染引擎设计与实践》P119 在场景中绘制位图):
osfg::ref_ptr<osg::DrawPixels> bmp= new osg::DrawPixels;
bmp->setPosition( osg::Vec3( 0.0, 0.0, 0.0));
bmp->setImage( osgDB::readImageFile("***.png"));
osg::ref_ptr< osg::Geode> geode= new osg::Geode;
geode->addDrawable( bmp.get());
方法二:有几何体,设置节点的状态集StateSet(参照OSG海军教程第2课:应用StateSet创建带有
纹理的几何体):
osg::Texture2D* KLN89FaceTexture = new osg::Texture2D;
KLN89FaceTexture->setDataVariance(osg::Object::DYNAMIC);
osg::Image* klnFace = osgDB::readImageFile("KLN89FaceB.tga");
KLN89FaceTexture->setImage(klnFace);
osg::StateSet* stateOne = new osg::StateSet();
stateOne->setTextureAttributeAndModes(0,KLN89FaceTexture,
osg::StateAttribute::ON);
geode->setStateSet(stateOne);