Osg-Osg实现雾效果(Qt5.14.2+osgE3.6.5+win10)-No23-OsgFog
.pro
1 QT += core gui widgets 2 TARGET = TestOsgQt 3 TEMPLATE = app 4 DEFINES += QT_DEPRECATED_WARNINGS 5 CONFIG += c++11 6 7 QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO 8 QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO 9 10 SOURCES += \ 11 main.cpp 12 13 HEADERS += 14 15 OsgDir = D:\\Gitee\\osg365R 16 CONFIG(release, debug|release) { 17 LIBS += -L$${OsgDir}/lib/ -losgDB -losgViewer -lOpenThreads -losgAnimation -losg \ 18 -losgEarth -losgEarthAnnotation -losgEarthFeatures -losgEarthSymbology -losgEarthUtil \ 19 -losgQOpenGL -losgUtil -losgText -losgTerrain -losgSim \ 20 -losgShadow -losgParticle -losgManipulator -losgGA -losgFX \ 21 -losgWidget 22 } else { 23 LIBS += -L$${OsgDir}/debug/lib/ -losgDBd -losgViewerd -lOpenThreadsd -losgAnimationd -losgd \ 24 -losgEarthd -losgEarthAnnotationd -losgEarthFeaturesd -losgEarthSymbologyd -losgEarthUtild \ 25 -losgQOpenGLd -losgUtild -losgTextd -losgTerraind -losgSimd \ 26 -losgShadowd -losgParticled -losgManipulatord -losgGAd -losgFXd \ 27 } 28 29 30 INCLUDEPATH += $${OsgDir}/include 31 DEPENDPATH += $${OsgDir}/include
main.cpp
1 #include <osgViewer/Viewer> 2 #include <osgDB/ReadFile> 3 #include <osg/Shape> 4 #include <osg/ShapeDrawable> 5 #include <osg/MatrixTransform> 6 #include <osg/Program> 7 #include <osgDB/ReadFile> 8 #include <osgDB/FileUtils> 9 #include <osgEarthUtil/Fog> 10 #include <osg/Fog> 11 12 int main() 13 { 14 // 加载牛 15 osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer; 16 osg::ref_ptr<osg::Node> geode = osgDB::readNodeFile("D:/Gitee/OsgTestQt/src/No23/tree.ive");//CreateNode(); 17 osg::ref_ptr<osg::Group> gp= new osg::Group; 18 gp->addChild(geode); 19 20 osg::ref_ptr<osg::Fog> fog = new osg::Fog; 21 fog->setDensity(0.01); 22 fog->setColor(osg::Vec4(1.0, 1.0, 1.0, 1.0)); 23 fog->setMode(osg::Fog::LINEAR); //osg::Fog::EXP //osg::Fog::EXP2 24 fog->setStart(10); 25 fog->setEnd(50); 26 gp->getOrCreateStateSet()->setAttributeAndModes(fog.get(), osg::StateAttribute::ON); 27 28 viewer->setSceneData(gp); 29 viewer->setUpViewInWindow(35, 35, 500, 500); 30 return viewer->run(); 31 // 以下代码也是雾,但是增加后,物体全变成白色了。 32 // osg::Fog* fog = new osg::Fog(); 33 // fog->setMode(osg::Fog::LINEAR); 34 // fog->setStart(500.0f); 35 // fog->setEnd(2500.0f); 36 // fog->setDensity(10); 37 // fog->setColor(osg::Vec4(0.5f, 0.5f, 0.5f, 1.0f)); 38 // fog->setUpdateCallback(new osgEarth::Util::FogCallback()); 39 // m_MapNode->getOrCreateStateSet()->setAttributeAndModes(fog, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); 40 // osgEarth::Util::FogEffect* fogEffect = new osgEarth::Util::FogEffect(); 41 // fogEffect->attach(m_MapNode->getOrCreateStateSet()); 42 //取消雾效 43 //fogEffect->detach(m_MapNode->getOrCreateStateSet()); 44 }
作者:疯狂Delphi
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
欢迎关注我,一起进步!扫描下方二维码即可加我