| 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 | #include <osgText/Text3D> |
|---|
| 35 | |
|---|
| 36 | extern int main_orig(int, char**); |
|---|
| 37 | extern int main_test(int, char**); |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | int main_size(int argc, char** argv) |
|---|
| 41 | { |
|---|
| 42 | osg::ArgumentParser arguments(&argc, argv); |
|---|
| 43 | |
|---|
| 44 | osgViewer::Viewer viewer(arguments); |
|---|
| 45 | |
|---|
| 46 | std::string fontFile("arial.ttf"); |
|---|
| 47 | while(arguments.read("-f",fontFile)) {} |
|---|
| 48 | |
|---|
| 49 | osg::ref_ptr<osgText::Font> font = osgText::readFontFile(fontFile); |
|---|
| 50 | if (!font) return 1; |
|---|
| 51 | OSG_NOTICE<<"Read font "<<fontFile<<" font="<<font.get()<<std::endl; |
|---|
| 52 | |
|---|
| 53 | osg::Geode* geode = new osg::Geode; |
|---|
| 54 | |
|---|
| 55 | geode->addDrawable( osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0f),osg::Vec3(1.0f,0.0,0.0),osg::Vec3(0.0f,0.0,1.0), 0.0, 0.0, 1.0, 1.0) ); |
|---|
| 56 | |
|---|
| 57 | osgText::Text3D* text3d = new osgText::Text3D; |
|---|
| 58 | text3d->setPosition(osg::Vec3(1.0f,0.0f,0.0f)); |
|---|
| 59 | text3d->setFont(osgText::readFontFile("arial.ttf")); |
|---|
| 60 | text3d->setCharacterSizeMode(osgText::Text3D::OBJECT_COORDS); |
|---|
| 61 | text3d->setCharacterSize(1.0f); |
|---|
| 62 | text3d->setCharacterDepth(0.1f); |
|---|
| 63 | text3d->setAxisAlignment(osgText::Text3D::XZ_PLANE); |
|---|
| 64 | text3d->setText("This is a size test"); |
|---|
| 65 | |
|---|
| 66 | geode->addDrawable(text3d); |
|---|
| 67 | |
|---|
| 68 | viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); |
|---|
| 69 | viewer.addEventHandler(new osgViewer::StatsHandler); |
|---|
| 70 | |
|---|
| 71 | viewer.setSceneData(geode); |
|---|
| 72 | |
|---|
| 73 | return viewer.run(); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | int main(int argc, char** argv) |
|---|
| 79 | { |
|---|
| 80 | osg::ArgumentParser arguments(&argc, argv); |
|---|
| 81 | |
|---|
| 82 | if (arguments.read("--test")) |
|---|
| 83 | { |
|---|
| 84 | return main_test(argc,argv); |
|---|
| 85 | } |
|---|
| 86 | else if (arguments.read("--original") || arguments.read("--orig")) |
|---|
| 87 | { |
|---|
| 88 | return main_orig(argc,argv); |
|---|
| 89 | } |
|---|
| 90 | else if (arguments.read("--size-test")) |
|---|
| 91 | { |
|---|
| 92 | return main_size(argc,argv); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | osgViewer::Viewer viewer(arguments); |
|---|
| 96 | |
|---|
| 97 | std::string fontFile("arial.ttf"); |
|---|
| 98 | while(arguments.read("-f",fontFile)) {} |
|---|
| 99 | |
|---|
| 100 | osg::ref_ptr<osgText::Font> font = osgText::readFontFile(fontFile); |
|---|
| 101 | if (!font) return 1; |
|---|
| 102 | OSG_NOTICE<<"Read font "<<fontFile<<" font="<<font.get()<<std::endl; |
|---|
| 103 | |
|---|
| 104 | std::string word("This is a new test."); |
|---|
| 105 | while (arguments.read("-w",word)) {} |
|---|
| 106 | |
|---|
| 107 | osg::ref_ptr<osgText::Style> style = new osgText::Style; |
|---|
| 108 | |
|---|
| 109 | float thickness = 0.1f; |
|---|
| 110 | while(arguments.read("--thickness",thickness)) {} |
|---|
| 111 | style->setThicknessRatio(thickness); |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | float r; |
|---|
| 115 | osg::ref_ptr<osgText::Bevel> bevel; |
|---|
| 116 | while(arguments.read("--rounded",r)) { bevel = new osgText::Bevel; bevel->roundedBevel2(r); } |
|---|
| 117 | while(arguments.read("--rounded")) { bevel = new osgText::Bevel; bevel->roundedBevel2(0.25); } |
|---|
| 118 | while(arguments.read("--flat",r)) { bevel = new osgText::Bevel; bevel->flatBevel(r); } |
|---|
| 119 | while(arguments.read("--flat")) { bevel = new osgText::Bevel; bevel->flatBevel(0.25); } |
|---|
| 120 | while(arguments.read("--bevel-thickness",r)) { if (bevel.valid()) bevel->setBevelThickness(r); } |
|---|
| 121 | |
|---|
| 122 | style->setBevel(bevel.get()); |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | while(arguments.read("--outline",r)) { style->setOutlineRatio(r); } |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | osgText::TextNode* text = new osgText::TextNode; |
|---|
| 129 | text->setText(word); |
|---|
| 130 | text->setFont(font.get()); |
|---|
| 131 | text->setStyle(style.get()); |
|---|
| 132 | text->setTextTechnique(new osgText::TextTechnique); |
|---|
| 133 | text->update(); |
|---|
| 134 | |
|---|
| 135 | viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); |
|---|
| 136 | viewer.addEventHandler(new osgViewer::StatsHandler); |
|---|
| 137 | viewer.setSceneData(text); |
|---|
| 138 | |
|---|
| 139 | return viewer.run(); |
|---|
| 140 | } |
|---|