/* OpenSceneGraph example, osgtext. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "GlyphGeometry.h" #include "TextNode.h" extern int main_orig(int, char**); extern int main_test(int, char**); int main_experimental(osg::ArgumentParser& arguments) { std::string fontFile("arial.ttf"); while(arguments.read("-f",fontFile)) {} std::string word("This is a simple test"); while(arguments.read("--ascii")) { word.clear(); for(unsigned int c=' '; c<=127;++c) { word.push_back(c); } } while(arguments.read("-w",word)) {} osg::ref_ptr font = osgText::readFontFile(fontFile); if (!font) return 1; OSG_NOTICE<<"Read font "<setNumberCurveSamples(numSamples); profile.print(std::cout); osg::ref_ptr group = new osg::Group; osg::Vec3 position; for(unsigned int i=0; i glyph = font->getGlyph3D(word[i]); if (!glyph) return 1; osg::ref_ptr transform = new osg::PositionAttitudeTransform; transform->setPosition(position); transform->setAttitude(osg::Quat(osg::inDegrees(90.0),osg::Vec3d(1.0,0.0,0.0))); position.x() += glyph->getHorizontalWidth(); osg::ref_ptr geode = new osg::Geode; osg::ref_ptr glyphGeometry = osgText::computeGlyphGeometry(glyph.get(), thickness, width); osg::ref_ptr textGeometry = osgText::computeTextGeometry(glyphGeometry.get(), profile, width); osg::ref_ptr shellGeometry = outline ? osgText::computeShellGeometry(glyphGeometry.get(), profile, width) : 0; if (textGeometry.valid()) geode->addDrawable(textGeometry.get()); if (shellGeometry.valid()) geode->addDrawable(shellGeometry.get()); // create the normals if (smooth && textGeometry.valid()) { osgUtil::SmoothingVisitor::smooth(*textGeometry, osg::DegreesToRadians(creaseAngle)); } transform->addChild(geode.get()); group->addChild(transform.get()); } std::string filename; if (arguments.read("-o", filename)) osgDB::writeNodeFile(*group, filename); osgViewer::Viewer viewer(arguments); viewer.setSceneData(group.get()); viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); viewer.addEventHandler(new osgViewer::StatsHandler); return viewer.run(); } int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); if (arguments.read("--test")) { return main_test(argc,argv); } else if (arguments.read("--original") || arguments.read("--orig")) { return main_orig(argc,argv); } else if (arguments.read("--exp")) { return main_experimental(arguments); } osgViewer::Viewer viewer(arguments); std::string fontFile("arial.ttf"); while(arguments.read("-f",fontFile)) {} osg::ref_ptr font = osgText::readFontFile(fontFile); if (!font) return 1; OSG_NOTICE<<"Read font "< style = new osgText::Style; float thickness = 0.1f; while(arguments.read("--thickness",thickness)) {} style->setThicknessRatio(thickness); // set up any bevel if required float r; osg::ref_ptr bevel; while(arguments.read("--rounded",r)) { bevel = new osgText::Bevel; bevel->roundedBevel2(r); } while(arguments.read("--rounded")) { bevel = new osgText::Bevel; bevel->roundedBevel2(0.25); } while(arguments.read("--flat",r)) { bevel = new osgText::Bevel; bevel->flatBevel(r); } while(arguments.read("--flat")) { bevel = new osgText::Bevel; bevel->flatBevel(0.25); } while(arguments.read("--bevel-thickness",r)) { if (bevel.valid()) bevel->setBevelThickness(r); } style->setBevel(bevel); osgText::TextNode* text = new osgText::TextNode; text->setText(word); text->setFont(font.get()); text->setStyle(style.get()); text->setTextTechnique(new osgText::TextTechnique); text->update(); viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); viewer.addEventHandler(new osgViewer::StatsHandler); viewer.setSceneData(text); return viewer.run(); }