• OsgOsgShader着色器(Qt5.14.2+osgE3.6.5+win10)No18OsgShader


     

    无着色器

     有着色器

    相关资料:

    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
    View Code

    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 }
    View Code
  • 相关阅读:
    从scanf的学习接口设计
    特现C语言编程特点的小代码,itoa,数值转换成字符串
    So many good projects for studying C programming lanuage.
    重要算法代码
    选择一本C++教材
    4412 内核模块传参数
    4412 GPIO初始化
    4412 物理地址
    4412 杂项设备
    4412 Linux设备总线
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/16473271.html
Copyright © 2020-2023  润新知