osgText.String
表示一个带有文本内容的2D图元。它可以设置字体、大小、位置、颜色等属性。它是 osgText
模块中的一个类,可以通过 osgText/String
头文件来引用。
osgText::String::String();
osgText::String::String(const std::string& str, const osg::Vec4& color = osg::Vec4(1.0, 1.0, 1.0, 1.0));
第一个构造函数创建一个空的 osgText.String
对象。第二个构造函数创建一个带有文本内容的 osgText.String
对象。第一个参数为字符串,第二个参数为文本颜色(默认为白色)。
通过设置 osgText.String
的属性可以更改文本的外观效果。
void osgText::String::setText(const std::string& str);
std::string osgText::String::getText() const;
void osgText::String::setFont(osgText::Font* font);
osgText::Font* osgText::String::getFont() const;
void osgText::String::setCharacterSize(float size);
float osgText::String::getCharacterSize() const;
void osgText::String::setPosition(const osg::Vec3& pos);
void osgText::String::setPosition(float x, float y, float z);
osg::Vec3 osgText::String::getPosition() const;
void osgText::String::setAxisAlignment(osgText::String::AxisAlignment alignment);
osgText::String::AxisAlignment osgText::String::getAxisAlignment() const;
void osgText::String::setColor(const osg::Vec4& color);
osg::Vec4 osgText::String::getColor() const;
setText
:设置文本内容。getText
:获取文本内容。setFont
:设置字体。getFont
:获取字体。setCharacterSize
:设置字符大小。getCharacterSize
:获取字符大小。setPosition
:设置位置。getPosition
:获取位置。setAxisAlignment
:设置字符串的对齐方式(水平、竖直等)。getAxisAlignment
:获取字符串的对齐方式。setColor
:设置文本颜色。getColor
:获取文本颜色。osgText::String* text = new osgText::String("Hello, World!");
text->setPosition(50.0f, 50.0f, 0.0f);
text->setCharacterSize(20.0f);
text->setColor(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));