Osg-OsgShader着色器(Qt5.14.2+osgE3.6.5+win10)-No18-OsgShader
无着色器
有着色器
相关资料:
https://blog.51cto.com/u_15127583/4054561 原文
实例代码:
.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 #ifdef _WIN32 2 #include <Windows.h> 3 #endif // _WIN32 4 5 #include <osg/Group> 6 #include <osg/Camera> 7 #include <osgDB/ReadFile> 8 #include <osg/Node> 9 10 #include <osg/Geometry> 11 #include <osg/Image> 12 #include <osg/ShapeDrawable> 13 #include <osg/Texture2D> 14 15 #include <osg/MatrixTransform> 16 #include <osg/AnimationPath> 17 18 #include <osgViewer/Viewer> 19 #include <osgViewer/ViewerEventHandlers> 20 21 #include <osgGA/DriveManipulator> 22 #include <osgGA/GUIEventHandler> 23 #include <osgGA/GUIEventAdapter> 24 #include <osgGA/GUIActionAdapter> 25 26 #include <osgGA/AnimationPathManipulator> 27 #include <osgGA/KeySwitchMatrixManipulator> 28 29 #include <osgUtil/LineSegmentIntersector> 30 31 #include <iostream> 32 using namespace std; 33 34 //顶点着色器 35 static const char* vertShader = { 36 "varying vec4 color;\n" 37 "void main(void)\n" 38 "{\n" 39 "color = gl_Vertex;\n" 40 "gl_Position=gl_ModelViewProjectionMatrix*gl_Vertex;\n" 41 "}\n" 42 }; 43 44 //片元着色器 45 static const char* fragShader = { 46 "varying vec4 color;\n" 47 "void main(void)\n" 48 "{\n" 49 " gl_FragColor = clamp(color,0.1,0.8);\n" 50 "}\n" 51 }; 52 53 int main() 54 { 55 osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer; 56 osg::ref_ptr<osg::Group> group1 = new osg::Group; 57 osg::ref_ptr<osg::Program> program1 = new osg::Program; 58 osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("D:/Gitee/OsgTestQt/src/No18-OsgShader/cessna.osgb"); 59 60 osg::ref_ptr<osg::StateSet> stateset1 = node1->getOrCreateStateSet(); 61 62 program1->addShader(new osg::Shader(osg::Shader::VERTEX, vertShader)); 63 program1->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragShader)); 64 // stateset1->setAttributeAndModes(program1, osg::StateAttribute::ON); 65 66 group1->addChild(node1.get()); 67 viewer1->setSceneData(group1); 68 viewer1->setUpViewInWindow(200, 200, 800, 600, 0); 69 70 return viewer1->run(); 71 }
作者:疯狂Delphi
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
欢迎关注我,一起进步!扫描下方二维码即可加我