zoukankan      html  css  js  c++  java
  • osg HUD 背景图片设置

    #ifdef _WIN32
    #include <Windows.h>
    #endif // _WIN32
    #include<iostream>
    
    #include <osgViewer/Viewer>
    #include <osgViewer/ViewerEventHandlers> 
    #include <osgViewer/CompositeViewer> 
    
    #include <osgDB/ReadFile>
    
    #include <osg/Geode>
    #include <osg/Node>
    #include <osg/Geometry>
    #include <osg/GraphicsContext>
    #include <osg/ShapeDrawable>
    #include <osg/Material>
    #include <osg/Image>
    #include <osg/Texture2D>
    #include <osg/TexEnv>
    #include <osg/TexGen>
    #include <osg/NodeVisitor>
    #include <osg/MatrixTransform>
    #include <osg/PositionAttitudeTransform>
    #include <osg/AnimationPath>
    #include <osg/Matrixd>
    #include <osg/PagedLOD>
    #include <osg/Camera>
    #include <osgText/Text>
    
    #include <osgGA/TrackballManipulator>
    #include <osgGA/GUIEventHandler>
    #include <osgGA/CameraManipulator>
    #include <osgGA/StandardManipulator>
    #include <osgGA/OrbitManipulator>
    #include <osgGA/TrackballManipulator>
    
    #include <osgUtil/IntersectionVisitor>
    #include <osgUtil/LineSegmentIntersector>
    
    osg::Camera* createBackground(std::string strImg)
    {
        osg::ref_ptr<osg::Geode> geode1 = new osg::Geode;
        osg::ref_ptr<osg::Geometry> geometry1 = new osg::Geometry;
        osg::ref_ptr<osg::Camera> camera1 = new osg::Camera;
    
        camera1->setAllowEventFocus(false);
        camera1->setProjectionMatrixAsOrtho2D(0, 960, 0, 600);
        camera1->setViewport(0, 0, 960, 600);
    
        camera1->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
        camera1->setRenderOrder(osg::Camera::PRE_RENDER);
        camera1->setClearMask(GL_DEPTH_BUFFER_BIT  |  GL_COLOR_BUFFER_BIT);
        //camera1->setClearColor(osg::Vec4());
        camera1->setViewMatrix(osg::Matrix::identity());
    
        //压入顶点
        osg::ref_ptr<osg::Vec3Array> vertex = new osg::Vec3Array;
        vertex->push_back(osg::Vec3(0.0,0.0,0.0));
        vertex->push_back(osg::Vec3(960.0, 0.0, 0.0));
        vertex->push_back(osg::Vec3(960.0, 600.0, 0.0));
        vertex->push_back(osg::Vec3(0.0, 600.0, 0.0));
        geometry1->setVertexArray(vertex);
    
        //压入法线
        osg::ref_ptr<osg::Vec3Array> norml = new osg::Vec3Array;
        norml->push_back(osg::Vec3(0.0, 0.0, 1.0));
        geometry1->setNormalArray(norml);
        geometry1->setNormalBinding(osg::Geometry::BIND_OVERALL);
    
        //纹理坐标
        osg::ref_ptr<osg::Vec2Array> coord = new osg::Vec2Array;
        coord->push_back(osg::Vec2(0.0,0.0));
        coord->push_back(osg::Vec2(1.0, 0.0));
        coord->push_back(osg::Vec2(1.0, 1.0));
        coord->push_back(osg::Vec2(0.0, 1.0));
        geometry1->setTexCoordArray(0, coord);
        geometry1->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, 4));
    
        osg::ref_ptr<osg::Image> img1 = osgDB::readImageFile(strImg);
        if (!img1.valid())
        {
            std::cout << "" << std::endl;
        }
    
        osg::ref_ptr<osg::Texture2D> texture2d = new osg::Texture2D;
        texture2d->setImage(0, img1);
        geometry1->getOrCreateStateSet()->setTextureAttributeAndModes(0,texture2d,osg::StateAttribute::ON);
    
    
        camera1->addChild(geode1);
        geode1->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
        geode1->addDrawable(geometry1);
    
    
        return camera1.release();
    }
    
    
    int main()
    {
        osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer;
        osg::ref_ptr<osg::Group> group1 = new osg::Group;
    
        osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("D:\参考手册\BIM\osg\build20190628.osgb");
    
        group1->addChild(createBackground("D:\参考手册\images\104.jpg"));
        group1->addChild(node1.get());
    
        viewer1->getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT);
        viewer1->setSceneData(group1.get());
        viewer1->setUpViewInWindow(200, 200, 960, 600, 0);
    
        return viewer1->run();
    }

  • 相关阅读:
    KnockoutJS 3.X API 第五章 高级应用(4) 自定义处理逻辑
    KnockoutJS 3.X API 第五章 高级应用(3) 虚拟元素绑定
    KnockoutJS 3.X API 第五章 高级应用(2) 控制后代绑定
    KnockoutJS 3.X API 第五章 高级应用(1) 创建自定义绑定
    KnockoutJS 3.X API 第四章(14) 绑定语法细节
    KnockoutJS 3.X API 第四章(13) template绑定
    KnockoutJS 3.X API 第四章 表单绑定(12) selectedOptions、uniqueName绑定
    KnockoutJS 3.X API 第四章 表单绑定(11) options绑定
    KnockoutJS 3.X API 第四章 表单绑定(10) textInput、hasFocus、checked绑定
    KnockoutJS 3.X API 第四章 表单绑定(9) value绑定
  • 原文地址:https://www.cnblogs.com/herd/p/11116470.html
Copyright © 2011-2022 走看看