Osg-OSG利用DrawPixels实现裁剪(Qt5.14.2+osgE3.6.5+win10)-No26-DrawPixels
相关资料:
https://blog.csdn.net/wb175208/article/details/88551782
实例代表:
.pro
1 QT += core gui widgets 2 QT += opengl 3 TARGET = TestOsgQt 4 TEMPLATE = app 5 DEFINES += QT_DEPRECATED_WARNINGS 6 CONFIG += c++11 7 8 SOURCES += \ 9 main.cpp 10 11 HEADERS += 12 13 OsgDir = D:\\Gitee\\osg365R 14 CONFIG(release, debug|release) { 15 LIBS += -L$${OsgDir}/lib/ -losgDB -losgViewer -lOpenThreads -losgAnimation -losg \ 16 -losgEarth -losgEarthAnnotation -losgEarthFeatures -losgEarthSymbology -losgEarthUtil \ 17 -losgQOpenGL -losgUtil -losgText -losgTerrain -losgSim \ 18 -losgShadow -losgParticle -losgManipulator -losgGA -losgFX \ 19 -losgWidget 20 } else { 21 LIBS += -L$${OsgDir}/debug/lib/ -losgDBd -losgViewerd -lOpenThreadsd -losgAnimationd -losgd \ 22 -losgEarthd -losgEarthAnnotationd -losgEarthFeaturesd -losgEarthSymbologyd -losgEarthUtild \ 23 -losgQOpenGLd -losgUtild -losgTextd -losgTerraind -losgSimd \ 24 -losgShadowd -losgParticled -losgManipulatord -losgGAd -losgFXd \ 25 } 26 27 LIBS += -lOpenGL32 28 LIBS += -lGlU32 29 30 INCLUDEPATH += $${OsgDir}/include 31 DEPENDPATH += $${OsgDir}/include
main.cpp
1 #include <QApplication> 2 3 #include <osg/Node> 4 #include <osg/Group> 5 #include <osg/Geode> 6 #include <osg/Geometry> 7 #include <osg/Texture2D> 8 #include <osg/StateSet> 9 #include <osg/PositionAttitudeTransform> 10 #include <osgViewer/Viewer> 11 #include <osgDB/ReadFile> 12 #include <osgParticle/PrecipitationEffect> 13 // 雨雪效果 14 #include <osg/MatrixTransform> 15 // 粒子效果 16 #include <osgParticle/PrecipitationEffect> 17 #include <osgParticle/Particle> 18 #include <osgParticle/LinearInterpolator> 19 #include <osgParticle/ParticleSystem> 20 #include <osgParticle/RandomRateCounter> 21 #include <osgParticle/PointPlacer> 22 #include <osgParticle/RadialShooter> 23 #include <osgParticle/ModularEmitter> 24 #include <osgParticle/ParticleSystemUpdater> 25 #include <osgParticle/ModularProgram> 26 #include <osgUtil/Optimizer> 27 #include <osgUtil/Simplifier> 28 #include <osgParticle/FireEffect> 29 // 雾 30 #include <osg/Fog> 31 #include <osgDB/ReadFile> 32 #include <osgViewer/Viewer> 33 #include <osg/StateSet> 34 #include <osg/StateAttribute> 35 #include <osgViewer/ViewerEventHandlers> 36 #include <osgWidget/ViewerEventHandlers> 37 // 裁剪 38 #include <osg/DrawPixels> 39 // 40 #include <QDebug> 41 42 int main(int argc, char *argv[]) 43 { 44 osg::ref_ptr<osg::Group> root = new osg::Group; 45 osg::ref_ptr<osg::Geode> geode = new osg::Geode; 46 47 osg::ref_ptr<osg::DrawPixels> image = new osg::DrawPixels; 48 image->setPosition(osg::Vec3(0.0, 0.0, 0.0)); 49 //裁剪区域 50 image->setSubImageDimensions(200, 200, 200, 200); 51 image->setImage(osgDB::readImageFile("D:\\Gitee\\data\\1.jpg")); 52 53 geode->addChild(image); 54 root->addChild(geode); 55 56 osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer(); 57 viewer->addEventHandler(new osgViewer::WindowSizeHandler()); 58 viewer->setSceneData(root.get()); 59 viewer->setUpViewInWindow(50,50,500,400); 60 61 viewer->realize(); 62 viewer->run(); 63 }
作者:疯狂Delphi
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
欢迎关注我,一起进步!扫描下方二维码即可加我