|
osg::TextureCubeMap* readCubeMap()
{
osg::TextureCubeMap* cubemap = new osg::TextureCubeMap;
osg::Image* imagePosX = osgDB::readImageFile("qing.exr");
osg::Image* imageNegX = osgDB::readImageFile("qing.exr");
osg::Image* imagePosY = osgDB::readImageFile("qing.exr");
osg::Image* imageNegY = osgDB::readImageFile("qing.exr");
osg::Image* imagePosZ = osgDB::readImageFile("qing.exr");
osg::Image* imageNegZ = osgDB::readImageFile("qing.exr");
if (imagePosX && imageNegX && imagePosY && imageNegY && imagePosZ && imageNegZ)
{
//设置立方图的六个面的贴图
cubemap->setImage(osg::TextureCubeMap:OSITIVE_X, imagePosX);
cubemap->setImage(osg::TextureCubeMap::NEGATIVE_X, imageNegX);
cubemap->setImage(osg::TextureCubeMap::POSITIVE_Y, imagePosY);
cubemap->setImage(osg::TextureCubeMap::NEGATIVE_Y, imageNegY);
cubemap->setImage(osg::TextureCubeMap::POSITIVE_Z, imagePosZ);
cubemap->setImage(osg::TextureCubeMap::NEGATIVE_Z, imageNegZ);
//设置纹理环绕模式
cubemap->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
cubemap->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
cubemap->setWrap(osg::Texture::WRAP_R, osg::Texture::CLAMP_TO_EDGE);
//设置滤波:线形和mipmap
cubemap->setFilter(osg::Texture::MIN_FILTER, osg::Texture:INEAR_MIPMAP_LINEAR);
cubemap->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
}
return cubemap;
}
//设置立方图纹理
osg::TextureCubeMap* skymap = readCubeMap();
stateset->setTextureAttributeAndModes(0, skymap, osg::StateAttribute::ON| osg::StateAttribute::OVERRIDE);
stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
stateset->setMode( GL_CULL_FACE, osg::StateAttribute::OFF );
osg:rawable* drawable = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),70.0));
//把球体加入到叶节点
osg::Geode* geode = new osg::Geode;
geode->setCullingActive(false);
geode->setStateSet( stateset );
geode->addDrawable(drawable);
把上面的cubemap赋给 Sphere ,球显示出来了,但没有纹理,请问一下可能的原因是什么?
(跟踪发现cubemap的6个image都有内容,但就是显不出来,只能看到一个白球。如果用jpg的图片就可以显示出来)
期盼您的回复 |
|