osgText::Text osg字体

 

#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* createTextHUD()
{
    osg::ref_ptr<osg::Geode> geode1 = new osg::Geode;
    osg::ref_ptr<osgText::Text> text1 = new osgText::Text;
    osg::ref_ptr<osg::Camera> camera1 = new osg::Camera;

    camera1->setViewMatrix(osg::Matrix::identity());
    camera1->setRenderOrder(osg::Camera::POST_RENDER);
    camera1->setClearMask(GL_DEPTH_BUFFER_BIT);

    camera1->setAllowEventFocus(false);
    camera1->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
    camera1->setProjectionMatrixAsOrtho2D(-20, 600, -20, 400);

    text1->setFont("Fonts/simhei.ttf");
    text1->setCharacterSize(50);
    text1->setText(L"OSG 中文字体");
    text1->setPosition(osg::Vec3(0.0,0.0,0.0));

    geode1->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
    geode1->addDrawable(text1);

    camera1->addChild(geode1.get());
    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");
    osg::ref_ptr<osg::Node> node2 = osgDB::readNodeFile("D:\\参考手册\\BIM\\osg\\build1.osgb");

    group1->addChild(node2.get());
    group1->addChild(createTextHUD());

    viewer1->setSceneData(group1.get());
    viewer1->setUpViewInWindow(200,200,800,600,0);

    viewer1->run();
}

 

 

posted @ 2019-06-29 20:58  西北逍遥  阅读(1415)  评论(0编辑  收藏  举报