Osg-Osg之特效OsgFXOutline(Qt5.14.2+osgE3.6.5+win10)-No14-OsgFXOutline

 

.pro

 1 QT       += core gui widgets
 2 TARGET = TestOsgQt
 3 TEMPLATE = app
 4 DEFINES += QT_DEPRECATED_WARNINGS
 5 CONFIG += c++11
 6 
 7 SOURCES += \
 8         main.cpp
 9 
10 HEADERS +=
11 
12 OsgDir = D:\\Gitee\\osg365R
13 CONFIG(release, debug|release) {
14         LIBS += -L$${OsgDir}/lib/ -losgDB -losgViewer -lOpenThreads -losgAnimation -losg \
15                                   -losgEarth -losgEarthAnnotation -losgEarthFeatures -losgEarthSymbology -losgEarthUtil \
16                                   -losgQOpenGL -losgUtil -losgText -losgTerrain -losgSim \
17                                   -losgShadow -losgParticle -losgManipulator -losgGA -losgFX \
18                                   -losgWidget
19 } else {
20         LIBS += -L$${OsgDir}/debug/lib/ -losgDBd -losgViewerd -lOpenThreadsd -losgAnimationd -losgd \
21                                   -losgEarthd -losgEarthAnnotationd -losgEarthFeaturesd -losgEarthSymbologyd -losgEarthUtild \
22                                   -losgQOpenGLd -losgUtild -losgTextd -losgTerraind -losgSimd \
23                                   -losgShadowd -losgParticled -losgManipulatord -losgGAd -losgFXd \
24 }
25 
26 
27 INCLUDEPATH += $${OsgDir}/include
28 DEPENDPATH += $${OsgDir}/include
View Code

main.cpp

 1 #include <QApplication>
 2 #ifdef _WIN32
 3 #include <Windows.h>
 4 #endif // _WIN32
 5 #include <iostream>
 6 //#include <math.h>
 7 
 8 #include <osg/Node>
 9 #include <osg/Group>
10 #include <osgDB/ReadFile>
11 #include <osgViewer/Viewer>
12 #include <osg/Geode>
13 #include <osg/ShapeDrawable>
14 #include <osg/Material>
15 #include <osg/Image>
16 #include <osg/Texture2D>
17 #include <osg/BoundingSphere>
18 #include <osg/LineWidth>
19 #include <osg/Point>
20 #include <osg/TexGen>
21 #include <osg/TexEnv>
22 
23 //#include <osg/TessellationHints>
24 //#include <osg/NodePath>
25 #include <osgGA/GUIEventHandler>
26 #include <osgGA/GUIEventAdapter>
27 
28 #include <osg/PositionAttitudeTransform>
29 #include <osgViewer/ViewerEventHandlers>
30 #include <osg/MatrixTransform>
31 #include <OpenThreads/Thread>
32 #include <osg/LightSource>
33 #include <osg/Light>
34 
35 #include <osgFX/Scribe>
36 #include <osgFX/Outline>
37 
38 int main()
39 {
40     osg::Geode *geode = new osg::Geode;
41     geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(), 2)));
42 
43     osgFX::Outline *outline = new osgFX::Outline;
44     outline->addChild(geode);
45     outline->setColor(osg::Vec4(1.0, 0.0, 0.0, 1.0));
46     outline->setWidth(5.0f);
47 
48     osgViewer::Viewer viewer;
49 
50     osg::Group *root = new osg::Group;
51     root->addChild(outline);
52     viewer.setUpViewInWindow(100, 100, 500, 500);
53     viewer.setSceneData(root);
54     //Outline类的使用需要先用0清空StencilBuffer
55     unsigned int clearMask = viewer.getCamera()->getClearMask();
56     viewer.getCamera()->setClearMask(clearMask | GL_STENCIL_BUFFER_BIT);
57     viewer.getCamera()->setClearStencil(0);
58     viewer.run();
59 }
View Code

 

 

posted on 2022-07-11 18:16  疯狂delphi  阅读(150)  评论(0编辑  收藏  举报

导航