osg绘制3d文字

发布时间 2024-01-02 21:43:23作者: 西北逍遥

 

#include <osg/Geode>
#include <osgText/Text3D>

int main()
{
    // 创建场景图
    osg::ref_ptr<osg::Group> root = new osg::Group();
    osg::ref_ptr<osg::Geode> geode = new osg::Geode();
    root->addChild(geode.get());

    // 创建文本对象
    osgText::Text3D* text = new osgText::Text3D();
    text->setFont("fonts/arial.ttf"); // 设置字体文件路径
    text->setCharacterSize(24); // 设置字符大小
    text->setAlignment(osgText::TextBase::ALIGN_CENTER); // 设置对齐方式
    text->setText("Hello, World!"); // 设置文本内容

    // 添加文本对象到场景图中
    geode->addChild(text);

    // 创建渲染器并运行渲染循环
    osgViewer::Viewer viewer;
    viewer.setSceneData(root.get());
    viewer.run();

    return 0;
}

 

 

 

 

============