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

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

Moved TextNode? from osgText into example/osgtext3D in prep for 3.0

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