root/OpenSceneGraph/trunk/examples/osgtext3D/osgtext3D.cpp @ 11774

Revision 11774, 3.4 kB (checked in by robert, 4 years ago)

Build fixes for when OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION is disabled

Line 
1/* OpenSceneGraph example, osgtext.
2*
3*  Permission is hereby granted, free of charge, to any person obtaining a copy
4*  of this software and associated documentation files (the "Software"), to deal
5*  in the Software without restriction, including without limitation the rights
6*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*  copies of the Software, and to permit persons to whom the Software is
8*  furnished to do so, subject to the following conditions:
9*
10*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
16*  THE SOFTWARE.
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
35extern int main_orig(int, char**);
36extern int main_test(int, char**);
37
38int 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    // set up any bevel if required
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.get());
79
80    // set up outline.
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}
Note: See TracBrowser for help on using the browser.