#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;\n"
    "void main(void)\n"
    "{\n"
        "color = gl_Vertex;\n"
        "gl_Position=gl_ModelViewProjectionMatrix*gl_Vertex;\n"
    "}\n"
};

//片元着色器
static const char* fragShader = {
    "varying vec4 color;\n"
    "void main(void)\n"
    "{\n"
    "    gl_FragColor = clamp(color,0.1,0.8);\n"
    "}\n"
};

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();
}

osg Shader 着色器

osg Shader 着色器

 

相关文章:

  • 2021-09-29
  • 2021-06-01
  • 2021-04-19
  • 2021-10-21
  • 2022-01-20
  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2021-08-03
  • 2022-12-23
  • 2021-09-03
相关资源
相似解决方案