zoukankan      html  css  js  c++  java
  • osg Shader 着色器

    #ifdef _WIN32
    #include <Windows.h>
    #endif // _WIN32
    
    #include <osg/Group>
    #include <osg/Camera>
    #include <osgDB/ReadFile>
    #include <osg/Node>
    
    #include <osg/Geometry>
    #include <osg/Image>
    #include <osg/ShapeDrawable>
    #include <osg/Texture2D>
    
    #include <osg/MatrixTransform>
    #include <osg/AnimationPath>
    
    #include <osgViewer/Viewer>
    #include <osgViewer/ViewerEventHandlers>
    
    #include <osgGA/DriveManipulator>
    #include <osgGA/GUIEventHandler>
    #include <osgGA/GUIEventAdapter>
    #include <osgGA/GUIActionAdapter>
    
    #include <osgGA/AnimationPathManipulator>
    #include <osgGA/KeySwitchMatrixManipulator>
    
    #include <osgUtil/LineSegmentIntersector>
    
    #include <iostream>
    using namespace std;
    
    //顶点着色器
    static const char* vertShader = {
        "varying vec4 color;
    "
        "void main(void)
    "
        "{
    "
            "color = gl_Vertex;
    "
            "gl_Position=gl_ModelViewProjectionMatrix*gl_Vertex;
    "
        "}
    "
    };
    
    //片元着色器
    static const char* fragShader = {
        "varying vec4 color;
    "
        "void main(void)
    "
        "{
    "
        "    gl_FragColor = clamp(color,0.1,0.8);
    "
        "}
    "
    };
    
    int main()
    {
        osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer;
        osg::ref_ptr<osg::Group> group1 = new osg::Group;
        osg::ref_ptr<osg::Program> program1 = new osg::Program;
        //osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("D:\参考手册\BIM\osg\四合院2019.osgb");
        osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("D:\参考手册\BIM\obj\person1.obj");
    
    
        osg::ref_ptr<osg::StateSet> stateset1 = node1->getOrCreateStateSet();
        
        program1->addShader(new osg::Shader(osg::Shader::VERTEX, vertShader));
        program1->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragShader));
        stateset1->setAttributeAndModes(program1, osg::StateAttribute::ON);
    
        group1->addChild(node1.get());
        viewer1->setSceneData(group1);
        viewer1->setUpViewInWindow(200, 200, 800, 600, 0);
    
        return viewer1->run();
    }

  • 相关阅读:
    codeforces——模拟
    线段树水题
    编码格式分类: 前后端传递数据的编码格式contentType
    爬虫之爬取求职小网站
    auth 模块使用篇
    后端获取前端的多个数据用getlist
    字符串值的替换
    单例的5种开启方式
    forms 组件的功能和使用
    cookie和session 的初步介绍
  • 原文地址:https://www.cnblogs.com/herd/p/11134093.html
Copyright © 2011-2022 走看看