• OSG显示文字——自定义显示文字函数


    #include <Windows.h>
     
    #include <osg/Geode>
     
    #include <osg/Geometry>
     
    #include <osgText/Text>
     
    #include <osgViewer/Viewer>
     
    #include <locale.h>
     
    #include <osgDB/ReadFile>
     
     
     
    void setupProperties(osgText::Text& textObject,osgText::Font* font,float size,const osg::Vec3& pos )
     
    {
     
     textObject.setFont(font);//
     
     textObject.setCharacterSize(size);//字体大小
     textObject.setPosition(pos);
     textObject.setColor(osg::Vec4(1.0,1.0,1.0,1.0));
     textObject.setAlignment(osgText::Text::CENTER_BOTTOM);//文字显示方向
     //textObject.setAxisAlignment(osgText::Text::SCREEN);//获取文字对称成方式正对屏幕方向
     //textObject.setCharacterSizeMode(osgText::Text::SCREEN_COORDS);//跟随视角不断变化,离物体越远,文字越大
     textObject.setAutoRotateToScreen(true);//跟随视角不断变化,但离物体越远,文字越小,和现实当中像类似
     textObject.setBackdropType(osgText::Text::OUTLINE);//对文字进行描边
     textObject.setBackdropColor(osg::Vec4(1.0,0.0,0.0,1.0));//描边颜色
     textObject.setDrawMode(osgText::Text::TEXT | osgText::Text::BOUNDINGBOX);//添加文字边框
     
     textObject.setAxisAlignment(osgText::Text::XZ_PLANE);//获取文字对称成方式
     
     
     
    }
     
     
     
    void createContent(osgText::Text& textObject,const char* string)
     
    {
     
        int requiredSize=mbstowcs(NULL,string,0);//如果mbstowcs第一参数为NULL那么返回字符串的数目
     
        wchar_t* wText=new wchar_t[requiredSize+1];
     
        mbstowcs(wText,string,requiredSize+1);//由char转换成wchar类型
     
        textObject.setText(wText);
     
        delete wText;
     
    }
     
     
     
    int main()
     
    {
     
        setlocale(LC_ALL,".936");// 配置地域化信息
     
        const char* titleString="木兰辞
    拟古决绝词简友";
     
        const char* textString={
     
            "人生若只如初见,何事秋风悲画扇;
    "
     
            "等闲变却故人心,却道故人心易变;
    "
     
            "骊山语罢倾销半,夜雨霖铃终不怨;
    "
     
            "何如薄幸锦衣郎,比翼连枝当日愿。"
     
        };
     
        osgText::Font* fontHei=osgText::readFontFile("C:\WINDOWS\Fonts\simhei.ttf");
     
        osgText::Font* fontKai=osgText::readFontFile("C:\WINDOWS\Fonts\simkai.ttf");
     
     
     
        osg::ref_ptr<osgText::Text> title=new osgText::Text;
     
        setupProperties(*title,fontHei,20.0f,osg::Vec3(0.0,0.0,0.0));
     
        createContent(*title,titleString);
     
     
     
        osg::ref_ptr<osgText::Text> text=new osgText::Text;
     
        setupProperties(*text,fontKai,15.0,osg::Vec3(0.0,0.0,-80.0f));
     
        createContent(*text,textString);
     
     
     
        osg::ref_ptr<osg::Geode> geode=new osg::Geode;
     
        geode->addDrawable(osg::createTexturedQuadGeometry(osg::Vec3(-150.0,1.0,-130.0),osg::Vec3(300.0,0.0,0.0),osg::Vec3(0.0,0.0,200.0),1.0,1.0));//创建一个写字板
     
     
     
        geode->addDrawable(title.get());
     
        geode->addDrawable(text.get());
     
        osgViewer::Viewer viewer;
     
        viewer.setSceneData(geode.get());
     
        return viewer.run();    
     
    }
  • 相关阅读:
    华为P20 无法投屏到电视
    configuration error &ndash; unknown item &lsquo;umask&rsquo; (notify administrator)
    oracle不支持update from的语法
    SQL Server 中update的小计
    sqlplus连接oracle数据库--密码含特殊字符
    redhat 7.6安装oracle 11gR2遇到两个问题
    ORA-15032 ORA-15028
    ORA-07391 sftopen error unable to open text file
    ORA-01017 invalid username/password logon denied
    Oracle CRS/GI 进程介绍
  • 原文地址:https://www.cnblogs.com/xiaocainiao2hao/p/5619926.html
Copyright © 2020-2023  润新知