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

 

转载于:https://www.cnblogs.com/herd/p/11134093.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值