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

 

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值