查看: 2505|回复: 2

透明度设置 在线等

[复制链接]

该用户从未签到

发表于 2011-6-27 10:07:41 | 显示全部楼层 |阅读模式
我使用jpeg图片对矩形进行贴图的,我想设置图片为半透明,能后看到它后面的图片,在osg里该咋设置啊,用这个代码没效果啊
osg::BlendColor *bc=new osg::BlendColor(osg::Vec4(1.0,0,0,0));
osg::BlendFunc * bf=new osg::BlendFunc();
bf->setSourceAlpha(osg::BlendFunc::CONSTANT_ALPHA);
bf->setDestinationAlpha(osg::BlendFunc::ONE_MINUS_CONSTANT_ALPHA);
stateset->setAttributeAndModes(bf,osg::StateAttribute::ON);
stateset->setAttributeAndModes(bc,osg::StateAttribute::ON);
stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
新手上路,各位大虾多多指教

该用户从未签到

发表于 2011-6-27 10:45:47 | 显示全部楼层
material有个settransparency的函数~

该用户从未签到

 楼主| 发表于 2011-6-30 15:47:24 | 显示全部楼层
本帖最后由 water_GIS 于 2011-6-30 15:49 编辑

回复 2# 朽木


   谢谢,问题解决了,用的BlendFun函数.
  osg::StateSet* stateset = geom->getOrCreateStateSet();
  stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF |
   osg::StateAttribute::PROTECTED);
  //打开融合模式(以保证ALPHA纹理正确)
  stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
  //禁止深度测试,几何体忽略已绘制物体的深度值
  stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
  stateset->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );

osg::BlendColor *bc=new osg::BlendColor(osg::Vec4(1.0,0,0,0));
osg::BlendFunc * bf=new osg::BlendFunc();
stateset->setAttributeAndModes(bf,osg::StateAttribute::ON);
stateset->setAttributeAndModes(bc,osg::StateAttribute::ON);
  bf->setSource(osg::BlendFunc::CONSTANT_ALPHA);
     bf->setDestination(osg::BlendFunc::ONE_MINUS_CONSTANT_ALPHA);
  bc->setConstantColor(osg::Vec4(1, 1, 1,0.4f));
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表