// create text which sits in 3D space such as would be inserted into a normal model osg::Group* create3DText(const osg::Vec3& center,float radius) { osg::Geode* geode = new osg::Geode; //////////////////////////////////////////////////////////////////////////////////////////////////////// // // Examples of how to set up axis/orientation alignments // float characterSize=radius*0.2f; osg::Vec3 pos(center.x()-radius*.5f,center.y()-radius*.5f,center.z()-radius*.5f); osgText::Text* text1 = new osgText::Text; text1->setFont(new osgText::Font(new osgQt::QFontImplementation(QFont("Times")))); text1->setCharacterSize(characterSize); text1->setPosition(pos); text1->setAxisAlignment(osgText::Text::XY_PLANE); text1->setText("XY_PLANE"); geode->addDrawable(text1); osgText::Text* text2 = new osgText::Text; text2->setFont(new osgText::Font(new osgQt::QFontImplementation(QFont("Times")))); text2->setCharacterSize(characterSize); text2->setPosition(pos); text2->setAxisAlignment(osgText::Text::YZ_PLANE); text2->setText("YZ_PLANE"); geode->addDrawable(text2); osgText::Text* text3 = new osgText::Text; text3->setFont(new osgText::Font(new osgQt::QFontImplementation(QFont("Times")))); text3->setCharacterSize(characterSize); text3->setPosition(pos); text3->setAxisAlignment(osgText::Text::XZ_PLANE); text3->setText("XZ_PLANE"); geode->addDrawable(text3); osgText::Text* text4 = new osgText::Text; text4->setFont(new osgText::Font(new osgQt::QFontImplementation(QFont("Times")))); text4->setCharacterSize(characterSize); text4->setPosition(center); text4->setAxisAlignment(osgText::Text::SCREEN); osg::Vec4 characterSizeModeColor(1.0f,0.0f,0.5f,1.0f); osgText::Text* text5 = new osgText::Text; text5->setColor(characterSizeModeColor); text5->setFont(new osgText::Font(new osgQt::QFontImplementation(QFont("Times")))); //text5->setCharacterSize(characterSize); text5->setCharacterSize(32.0f); // medium text5->setPosition(center - osg::Vec3(0.0, 0.0, 0.2)); text5->setAxisAlignment(osgText::Text::SCREEN); text5->setCharacterSizeMode(osgText::Text::SCREEN_COORDS); text5->setText("CharacterSizeMode SCREEN_COORDS(size 32.0)"); geode->addDrawable(text5); osgText::Text* text6 = new osgText::Text; text6->setColor(characterSizeModeColor); text6->setFont(new osgText::Font(new osgQt::QFontImplementation(QFont("Times")))); text6->setCharacterSize(characterSize); text6->setPosition(center - osg::Vec3(0.0, 0.0, 0.4)); text6->setAxisAlignment(osgText::Text::SCREEN); text6->setCharacterSizeMode(osgText::Text::OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT); text6->setText("CharacterSizeMode OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT"); geode->addDrawable(text6); osgText::Text* text7 = new osgText::Text; text7->setColor(characterSizeModeColor); text7->setFont(new osgText::Font(new osgQt::QFontImplementation(QFont("Times")))); text7->setCharacterSize(characterSize); text7->setPosition(center - osg::Vec3(0.0, 0.0, 0.6)); text7->setAxisAlignment(osgText::Text::SCREEN); text7->setCharacterSizeMode(osgText::Text::OBJECT_COORDS); text7->setText("CharacterSizeMode OBJECT_COORDS (default)"); geode->addDrawable(text7); #if 1 // reproduce outline bounding box compute problem with backdrop on. text4->setBackdropType(osgText::Text::OUTLINE); text4->setDrawMode(osgText::Text::TEXT | osgText::Text::BOUNDINGBOX); #endif text4->setText("SCREEN"); geode->addDrawable(text4); osg::ShapeDrawable* shape = new osg::ShapeDrawable(new osg::Sphere(center,characterSize*0.2f)); shape->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::ON); geode->addDrawable(shape); osg::Group* rootNode = new osg::Group; rootNode->addChild(geode); return rootNode; }
// create text which sits in 3D space such as would be inserted into a normal model osg::Group* create3DText(const osg::Vec3& center,float radius) { osg::Geode* geode = new osg::Geode; bool useVBOs = false; #if defined(OSG_GL3_AVAILABLE) && !defined(OSG_GL2_AVAILABLE) && !defined(OSG_GL1_AVAILABLE) useVBOs = true; osg::Program* program = new osg::Program; program->addShader(new osg::Shader(osg::Shader::VERTEX, gl3TextVertexShader)); program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl3TextFragmentShader)); geode->getOrCreateStateSet()->setAttributeAndModes(program, osg::StateAttribute::ON); #endif //////////////////////////////////////////////////////////////////////////////////////////////////////// // // Examples of how to set up axis/orientation alignments // float characterSize=radius*0.2f; osg::Vec3 pos(center.x()-radius*.5f,center.y()-radius*.5f,center.z()-radius*.5f); osgText::Text* text1 = new osgText::Text; text1->setUseVertexBufferObjects(useVBOs); text1->setFont("fonts/times.ttf"); text1->setCharacterSize(characterSize); text1->setPosition(pos); text1->setAxisAlignment(osgText::Text::XY_PLANE); text1->setText("XY_PLANE"); geode->addDrawable(text1); osgText::Text* text2 = new osgText::Text; text2->setUseVertexBufferObjects(useVBOs); text2->setFont("fonts/times.ttf"); text2->setCharacterSize(characterSize); text2->setPosition(pos); text2->setAxisAlignment(osgText::Text::YZ_PLANE); text2->setText("YZ_PLANE"); geode->addDrawable(text2); osgText::Text* text3 = new osgText::Text; text3->setUseVertexBufferObjects(useVBOs); text3->setFont("fonts/times.ttf"); text3->setCharacterSize(characterSize); text3->setPosition(pos); text3->setAxisAlignment(osgText::Text::XZ_PLANE); text3->setText("XZ_PLANE"); geode->addDrawable(text3); osg::Vec4 characterSizeModeColor(1.0f,0.0f,0.5f,1.0f); osgText::Text* text4 = new osgText::Text; text4->setUseVertexBufferObjects(useVBOs); text4->setFont("fonts/times.ttf"); text4->setCharacterSize(characterSize); text4->setPosition(center); text4->setAxisAlignment(osgText::Text::SCREEN); // reproduce outline bounding box compute problem with backdrop on. text4->setBackdropType(osgText::Text::OUTLINE); text4->setDrawMode(osgText::Text::TEXT | osgText::Text::BOUNDINGBOX); text4->setText("SCREEN"); geode->addDrawable(text4); osgText::Text* text5 = new osgText::Text; text5->setUseVertexBufferObjects(useVBOs); text5->setColor(characterSizeModeColor); text5->setFont("fonts/times.ttf"); //text5->setCharacterSize(characterSize); text5->setCharacterSize(32.0f); // medium text5->setPosition(center - osg::Vec3(0.0, 0.0, 0.2)); text5->setAxisAlignment(osgText::Text::SCREEN); text5->setCharacterSizeMode(osgText::Text::SCREEN_COORDS); text5->setDrawMode(osgText::Text::TEXT | osgText::Text::BOUNDINGBOX); text5->setText("CharacterSizeMode SCREEN_COORDS(size 32.0)"); geode->addDrawable(text5); osgText::Text* text6 = new osgText::Text; text6->setUseVertexBufferObjects(useVBOs); text6->setColor(characterSizeModeColor); text6->setFont("fonts/times.ttf"); text6->setCharacterSize(characterSize); text6->setPosition(center - osg::Vec3(0.0, 0.0, 0.4)); text6->setAxisAlignment(osgText::Text::SCREEN); text6->setCharacterSizeMode(osgText::Text::OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT); text6->setText("CharacterSizeMode OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT"); geode->addDrawable(text6); osgText::Text* text7 = new osgText::Text; text7->setUseVertexBufferObjects(useVBOs); text7->setColor(characterSizeModeColor); text7->setFont("fonts/times.ttf"); text7->setCharacterSize(characterSize); text7->setPosition(center - osg::Vec3(0.0, 0.0, 0.6)); text7->setAxisAlignment(osgText::Text::SCREEN); text7->setCharacterSizeMode(osgText::Text::OBJECT_COORDS); text7->setText("CharacterSizeMode OBJECT_COORDS (default)"); geode->addDrawable(text7); osg::ShapeDrawable* shape = new osg::ShapeDrawable(new osg::Sphere(center,characterSize*0.2f)); shape->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::ON); geode->addDrawable(shape); osg::Group* rootNode = new osg::Group; rootNode->addChild(geode); return rootNode; }