2007-12-10 23:15:56 +08:00
|
|
|
/* OpenSceneGraph example, osgtext.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2010-07-15 02:50:41 +08:00
|
|
|
#include <osg/ArgumentParser>
|
|
|
|
#include <osg/Geode>
|
|
|
|
#include <osg/Geometry>
|
2010-08-24 22:22:58 +08:00
|
|
|
#include <osg/CullFace>
|
2010-08-20 00:24:08 +08:00
|
|
|
#include <osg/TriangleIndexFunctor>
|
2010-07-15 02:50:41 +08:00
|
|
|
#include <osg/PositionAttitudeTransform>
|
2010-07-26 19:12:45 +08:00
|
|
|
#include <osgUtil/SmoothingVisitor>
|
2010-07-15 02:50:41 +08:00
|
|
|
#include <osgDB/WriteFile>
|
|
|
|
#include <osgGA/StateSetManipulator>
|
|
|
|
#include <osgUtil/Tessellator>
|
2007-12-10 23:15:56 +08:00
|
|
|
#include <osgViewer/Viewer>
|
|
|
|
#include <osgViewer/ViewerEventHandlers>
|
2010-07-15 02:50:41 +08:00
|
|
|
#include <osg/io_utils>
|
2007-12-10 23:15:56 +08:00
|
|
|
|
2010-11-17 18:16:45 +08:00
|
|
|
#include <osgText/Text3D>
|
2010-08-24 22:22:58 +08:00
|
|
|
|
2010-11-24 01:33:43 +08:00
|
|
|
#include "TextNode.h"
|
|
|
|
|
2010-07-15 02:50:41 +08:00
|
|
|
extern int main_orig(int, char**);
|
|
|
|
extern int main_test(int, char**);
|
2007-12-10 23:15:56 +08:00
|
|
|
|
2010-11-17 18:16:45 +08:00
|
|
|
|
|
|
|
int main_size(int argc, char** argv)
|
|
|
|
{
|
|
|
|
osg::ArgumentParser arguments(&argc, argv);
|
|
|
|
|
|
|
|
osgViewer::Viewer viewer(arguments);
|
|
|
|
|
|
|
|
std::string fontFile("arial.ttf");
|
|
|
|
while(arguments.read("-f",fontFile)) {}
|
|
|
|
|
|
|
|
osg::ref_ptr<osgText::Font> font = osgText::readFontFile(fontFile);
|
|
|
|
if (!font) return 1;
|
|
|
|
OSG_NOTICE<<"Read font "<<fontFile<<" font="<<font.get()<<std::endl;
|
|
|
|
|
|
|
|
osg::Geode* geode = new osg::Geode;
|
|
|
|
|
|
|
|
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) );
|
|
|
|
|
|
|
|
osgText::Text3D* text3d = new osgText::Text3D;
|
|
|
|
text3d->setPosition(osg::Vec3(1.0f,0.0f,0.0f));
|
|
|
|
text3d->setFont(osgText::readFontFile("arial.ttf"));
|
|
|
|
text3d->setCharacterSizeMode(osgText::Text3D::OBJECT_COORDS);
|
|
|
|
text3d->setCharacterSize(1.0f);
|
|
|
|
text3d->setCharacterDepth(0.1f);
|
|
|
|
text3d->setAxisAlignment(osgText::Text3D::XZ_PLANE);
|
|
|
|
text3d->setText("This is a size test");
|
|
|
|
|
|
|
|
geode->addDrawable(text3d);
|
|
|
|
|
|
|
|
viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
|
|
|
|
viewer.addEventHandler(new osgViewer::StatsHandler);
|
|
|
|
|
|
|
|
viewer.setSceneData(geode);
|
|
|
|
|
|
|
|
return viewer.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-09-03 16:26:46 +08:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
osg::ArgumentParser arguments(&argc, argv);
|
|
|
|
|
|
|
|
if (arguments.read("--test"))
|
|
|
|
{
|
|
|
|
return main_test(argc,argv);
|
|
|
|
}
|
|
|
|
else if (arguments.read("--original") || arguments.read("--orig"))
|
|
|
|
{
|
|
|
|
return main_orig(argc,argv);
|
|
|
|
}
|
2010-11-17 18:16:45 +08:00
|
|
|
else if (arguments.read("--size-test"))
|
|
|
|
{
|
|
|
|
return main_size(argc,argv);
|
|
|
|
}
|
2010-09-03 16:26:46 +08:00
|
|
|
|
|
|
|
osgViewer::Viewer viewer(arguments);
|
|
|
|
|
|
|
|
std::string fontFile("arial.ttf");
|
|
|
|
while(arguments.read("-f",fontFile)) {}
|
|
|
|
|
|
|
|
osg::ref_ptr<osgText::Font> font = osgText::readFontFile(fontFile);
|
|
|
|
if (!font) return 1;
|
|
|
|
OSG_NOTICE<<"Read font "<<fontFile<<" font="<<font.get()<<std::endl;
|
|
|
|
|
|
|
|
std::string word("This is a new test.");
|
|
|
|
while (arguments.read("-w",word)) {}
|
|
|
|
|
2010-09-03 23:03:42 +08:00
|
|
|
osg::ref_ptr<osgText::Style> style = new osgText::Style;
|
|
|
|
|
2010-09-06 23:43:59 +08:00
|
|
|
float thickness = 0.1f;
|
2010-09-03 23:03:42 +08:00
|
|
|
while(arguments.read("--thickness",thickness)) {}
|
|
|
|
style->setThicknessRatio(thickness);
|
|
|
|
|
2010-09-06 23:43:59 +08:00
|
|
|
// set up any bevel if required
|
|
|
|
float r;
|
|
|
|
osg::ref_ptr<osgText::Bevel> bevel;
|
|
|
|
while(arguments.read("--rounded",r)) { bevel = new osgText::Bevel; bevel->roundedBevel2(r); }
|
|
|
|
while(arguments.read("--rounded")) { bevel = new osgText::Bevel; bevel->roundedBevel2(0.25); }
|
|
|
|
while(arguments.read("--flat",r)) { bevel = new osgText::Bevel; bevel->flatBevel(r); }
|
|
|
|
while(arguments.read("--flat")) { bevel = new osgText::Bevel; bevel->flatBevel(0.25); }
|
|
|
|
while(arguments.read("--bevel-thickness",r)) { if (bevel.valid()) bevel->setBevelThickness(r); }
|
|
|
|
|
2010-09-17 21:33:09 +08:00
|
|
|
style->setBevel(bevel.get());
|
2010-09-06 23:43:59 +08:00
|
|
|
|
2010-09-08 02:18:35 +08:00
|
|
|
// set up outline.
|
|
|
|
while(arguments.read("--outline",r)) { style->setOutlineRatio(r); }
|
|
|
|
|
|
|
|
|
2010-09-03 16:26:46 +08:00
|
|
|
osgText::TextNode* text = new osgText::TextNode;
|
|
|
|
text->setText(word);
|
2010-09-03 23:03:42 +08:00
|
|
|
text->setFont(font.get());
|
|
|
|
text->setStyle(style.get());
|
2010-09-03 16:26:46 +08:00
|
|
|
text->setTextTechnique(new osgText::TextTechnique);
|
|
|
|
text->update();
|
|
|
|
|
2010-09-06 23:43:59 +08:00
|
|
|
viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
|
|
|
|
viewer.addEventHandler(new osgViewer::StatsHandler);
|
2010-09-03 16:26:46 +08:00
|
|
|
viewer.setSceneData(text);
|
|
|
|
|
2010-11-17 18:16:45 +08:00
|
|
|
return viewer.run();
|
2010-09-03 16:26:46 +08:00
|
|
|
}
|