osg glsl添加半透明
一開始,沒有設置對,所以GLSL半透明沒出來,看了下例子,實際上很簡單,除了在片元著色器alpha設置外,還要啟動混合
osg::ref_ptr<osg::StateSet> stateset = geode->getOrCreateStateSet(); stateset->setMode(GL_BLEND, osg::StateAttribute::ON); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);廢話不多說,上代碼
//點集合啟動半透明
#include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
#include <osg/CoordinateSystemNode>
#include <osg/Switch>
#include <osg/Types>
#include <osgText/Text>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/StateSetManipulator>
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <osgGA/SphericalManipulator>
#include <osgGA/Device>
#include
#include <osg/Shader>
osg::ref_ptrosg::Geode createPointsGeode()
{
osg::ref_ptrosg::Geode geode = new osg::Geode;
osg::ref_ptrosg::Geometry geom = new osg::Geometry;
}
static const char * vertexShader =
{
“void main(void)\n”
“{\n”
" gl_Position = ftransform();\n"
“}\n”
};
static const char *psShader =
{
“void main(void)\n”
“{\n”
“gl_FragColor =vec4(0.0f,0.0f,1.0f,1.0f);\n”
“}\n”
};
int main()
{
osg::ref_ptrosg::Group grp = new osg::Group;
osg::ref_ptrosg::Geode geode = createPointsGeode();
grp->addChild(geode);
osg::ref_ptrosg::StateSet stateset = geode->getOrCreateStateSet();
stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
osg::ref_ptrosg::Shader vs = new osg::Shader(osg::Shader::VERTEX, vertexShader);
osg::ref_ptrosg::Shader ps = new osg::Shader(osg::Shader::FRAGMENT, psShader);
osg::ref_ptrosg::Program program = new osg::Program;
program->addShader(vs);
program->addShader(ps);
stateset->setAttribute(program, osg::StateAttribute::ON);
osg::ref_ptrosgViewer::Viewer viewer = new osgViewer::Viewer;
viewer->setSceneData(grp);
viewer->run();
}
總結
以上是生活随笔為你收集整理的osg glsl添加半透明的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 家用电器行业为什么需要订货管理系统
- 下一篇: Spring Security 自定义接