| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #include <osg/ArgumentParser> |
|---|
| 20 | #include <osg/Geode> |
|---|
| 21 | #include <osg/Geometry> |
|---|
| 22 | #include <osg/CullFace> |
|---|
| 23 | #include <osg/TriangleIndexFunctor> |
|---|
| 24 | #include <osg/PositionAttitudeTransform> |
|---|
| 25 | #include <osgUtil/SmoothingVisitor> |
|---|
| 26 | #include <osgDB/WriteFile> |
|---|
| 27 | #include <osgGA/StateSetManipulator> |
|---|
| 28 | #include <osgUtil/Tessellator> |
|---|
| 29 | #include <osgViewer/Viewer> |
|---|
| 30 | #include <osgViewer/ViewerEventHandlers> |
|---|
| 31 | #include <osg/io_utils> |
|---|
| 32 | |
|---|
| 33 | #include <osgText/TextNode> |
|---|
| 34 | |
|---|
| 35 | extern int main_orig(int, char**); |
|---|
| 36 | extern int main_test(int, char**); |
|---|
| 37 | |
|---|
| 38 | int main(int argc, char** argv) |
|---|
| 39 | { |
|---|
| 40 | osg::ArgumentParser arguments(&argc, argv); |
|---|
| 41 | |
|---|
| 42 | if (arguments.read("--test")) |
|---|
| 43 | { |
|---|
| 44 | return main_test(argc,argv); |
|---|
| 45 | } |
|---|
| 46 | else if (arguments.read("--original") || arguments.read("--orig")) |
|---|
| 47 | { |
|---|
| 48 | return main_orig(argc,argv); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | osgViewer::Viewer viewer(arguments); |
|---|
| 52 | |
|---|
| 53 | std::string fontFile("arial.ttf"); |
|---|
| 54 | while(arguments.read("-f",fontFile)) {} |
|---|
| 55 | |
|---|
| 56 | osg::ref_ptr<osgText::Font> font = osgText::readFontFile(fontFile); |
|---|
| 57 | if (!font) return 1; |
|---|
| 58 | OSG_NOTICE<<"Read font "<<fontFile<<" font="<<font.get()<<std::endl; |
|---|
| 59 | |
|---|
| 60 | std::string word("This is a new test."); |
|---|
| 61 | while (arguments.read("-w",word)) {} |
|---|
| 62 | |
|---|
| 63 | osg::ref_ptr<osgText::Style> style = new osgText::Style; |
|---|
| 64 | |
|---|
| 65 | float thickness = 0.1f; |
|---|
| 66 | while(arguments.read("--thickness",thickness)) {} |
|---|
| 67 | style->setThicknessRatio(thickness); |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | float r; |
|---|
| 71 | osg::ref_ptr<osgText::Bevel> bevel; |
|---|
| 72 | while(arguments.read("--rounded",r)) { bevel = new osgText::Bevel; bevel->roundedBevel2(r); } |
|---|
| 73 | while(arguments.read("--rounded")) { bevel = new osgText::Bevel; bevel->roundedBevel2(0.25); } |
|---|
| 74 | while(arguments.read("--flat",r)) { bevel = new osgText::Bevel; bevel->flatBevel(r); } |
|---|
| 75 | while(arguments.read("--flat")) { bevel = new osgText::Bevel; bevel->flatBevel(0.25); } |
|---|
| 76 | while(arguments.read("--bevel-thickness",r)) { if (bevel.valid()) bevel->setBevelThickness(r); } |
|---|
| 77 | |
|---|
| 78 | style->setBevel(bevel); |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | while(arguments.read("--outline",r)) { style->setOutlineRatio(r); } |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | osgText::TextNode* text = new osgText::TextNode; |
|---|
| 85 | text->setText(word); |
|---|
| 86 | text->setFont(font.get()); |
|---|
| 87 | text->setStyle(style.get()); |
|---|
| 88 | text->setTextTechnique(new osgText::TextTechnique); |
|---|
| 89 | text->update(); |
|---|
| 90 | |
|---|
| 91 | viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); |
|---|
| 92 | viewer.addEventHandler(new osgViewer::StatsHandler); |
|---|
| 93 | viewer.setSceneData(text); |
|---|
| 94 | |
|---|
| 95 | return viewer.run(); |
|---|
| 96 | } |
|---|