: Documentation : Code Snippets

In OpenSceneGraph, text objects are osg::Drawable objects, so they need to be added to an osg::Geode in order to be part of the scene graph. However, you can add many text objects to a single geode.

osg::Geode* textGeode = new osg::Geode();
osgText::Text* text = new osgText::Text();
text->setFont("tahoma.ttf");
text->setCharacterSize(16.0f);
text->setPosition(osg::Vec3(4, 4, 0));
text->setAlignment(osgText::Text::LEFT_BASE_LINE);
text->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
text->setText("Your text here");
textGeode->addDrawable(text);