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

Revision 11917, 4.7 kB (checked in by robert, 3 years ago)

Added quite size test.

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#include <osgText/Text3D>
35
36extern int main_orig(int, char**);
37extern int main_test(int, char**);
38
39
40int 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
78int 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    // set up any bevel if required
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    // set up outline.
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}
Note: See TracBrowser for help on using the browser.