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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM