| 39 | | |
| 40 | | int main_experimental(osg::ArgumentParser& arguments) |
| 41 | | { |
| 42 | | std::string fontFile("arial.ttf"); |
| 43 | | while(arguments.read("-f",fontFile)) {} |
| 44 | | |
| 45 | | std::string word("This is a simple test"); |
| 46 | | |
| 47 | | while(arguments.read("--ascii")) |
| 48 | | { |
| 49 | | word.clear(); |
| 50 | | for(unsigned int c=' '; c<=127;++c) |
| 51 | | { |
| 52 | | word.push_back(c); |
| 53 | | } |
| 54 | | } |
| 55 | | |
| 56 | | while(arguments.read("-w",word)) {} |
| 57 | | |
| 58 | | osg::ref_ptr<osgText::Font> font = osgText::readFontFile(fontFile); |
| 59 | | if (!font) return 1; |
| 60 | | OSG_NOTICE<<"Read font "<<fontFile<<" font="<<font.get()<<std::endl; |
| 61 | | |
| 62 | | bool useTessellator = true; |
| 63 | | while(arguments.read("-t") || arguments.read("--tessellate")) { useTessellator = true; } |
| 64 | | while(arguments.read("--no-tessellate")) { useTessellator = false; } |
| 65 | | |
| 66 | | float thickness = 5.0; |
| 67 | | while(arguments.read("--thickness",thickness)) {} |
| 68 | | |
| 69 | | float width = 20.0; |
| 70 | | while(arguments.read("--width",width)) {} |
| 71 | | |
| 72 | | float creaseAngle = 30.0f; |
| 73 | | while(arguments.read("--crease-angle",creaseAngle)) {} |
| 74 | | |
| 75 | | OSG_NOTICE<<"creaseAngle="<<creaseAngle<<std::endl; |
| 76 | | |
| 77 | | osgText::Bevel profile; |
| 78 | | float ratio = 0.5; |
| 79 | | while(arguments.read("--rounded",ratio)) { profile.roundedBevel(ratio); } |
| 80 | | while(arguments.read("--rounded2",ratio)) { profile.roundedBevel2(ratio); } |
| 81 | | while(arguments.read("--flat",ratio)) { profile.flatBevel(ratio); } |
| 82 | | |
| 83 | | bool outline = false; |
| 84 | | while(arguments.read("--outline")) { outline = true; } |
| 85 | | while(arguments.read("--no-outline")) { outline = false; } |
| 86 | | |
| 87 | | bool smooth = true; |
| 88 | | while(arguments.read("--flat-shaded")) { smooth = false; } |
| 89 | | while(arguments.read("--smooth")) { smooth = false; } |
| 90 | | |
| 91 | | unsigned int numSamples = 10; |
| 92 | | while(arguments.read("--samples", numSamples)) {} |
| 93 | | font->setNumberCurveSamples(numSamples); |
| 94 | | |
| 95 | | profile.print(std::cout); |
| 96 | | |
| 97 | | |
| 98 | | osg::ref_ptr<osg::Group> group = new osg::Group; |
| 99 | | osg::Vec3 position; |
| 100 | | |
| 101 | | for(unsigned int i=0; i<word.size(); ++i) |
| 102 | | { |
| 103 | | osg::ref_ptr<osgText::Glyph3D> glyph = font->getGlyph3D(word[i]); |
| 104 | | if (!glyph) return 1; |
| 105 | | |
| 106 | | osg::ref_ptr<osg::PositionAttitudeTransform> transform = new osg::PositionAttitudeTransform; |
| 107 | | transform->setPosition(position); |
| 108 | | transform->setAttitude(osg::Quat(osg::inDegrees(90.0),osg::Vec3d(1.0,0.0,0.0))); |
| 109 | | |
| 110 | | position.x() += glyph->getHorizontalWidth(); |
| 111 | | |
| 112 | | osg::ref_ptr<osg::Geode> geode = new osg::Geode; |
| 113 | | |
| 114 | | osg::ref_ptr<osg::Geometry> glyphGeometry = osgText::computeGlyphGeometry(glyph.get(), thickness, width); |
| 115 | | osg::ref_ptr<osg::Geometry> textGeometry = osgText::computeTextGeometry(glyphGeometry.get(), profile, width); |
| 116 | | osg::ref_ptr<osg::Geometry> shellGeometry = outline ? osgText::computeShellGeometry(glyphGeometry.get(), profile, width) : 0; |
| 117 | | if (textGeometry.valid()) geode->addDrawable(textGeometry.get()); |
| 118 | | if (shellGeometry.valid()) geode->addDrawable(shellGeometry.get()); |
| 119 | | |
| 120 | | // create the normals |
| 121 | | if (smooth && textGeometry.valid()) |
| 122 | | { |
| 123 | | osgUtil::SmoothingVisitor::smooth(*textGeometry, osg::DegreesToRadians(creaseAngle)); |
| 124 | | } |
| 125 | | |
| 126 | | transform->addChild(geode.get()); |
| 127 | | |
| 128 | | group->addChild(transform.get()); |
| 129 | | } |
| 130 | | |
| 131 | | std::string filename; |
| 132 | | if (arguments.read("-o", filename)) osgDB::writeNodeFile(*group, filename); |
| 133 | | |
| 134 | | osgViewer::Viewer viewer(arguments); |
| 135 | | viewer.setSceneData(group.get()); |
| 136 | | viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); |
| 137 | | viewer.addEventHandler(new osgViewer::StatsHandler); |
| 138 | | return viewer.run(); |
| 139 | | } |