diff --git a/examples/osgfont/osgfont.cpp b/examples/osgfont/osgfont.cpp index 5090422ce..f7c068acd 100644 --- a/examples/osgfont/osgfont.cpp +++ b/examples/osgfont/osgfont.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -57,30 +58,74 @@ osg::Camera* createOrthoCamera(double width, double height) return camera; } -osgText::Text* createLabel(const std::string& l, const std::string& fontfile, unsigned int size) +struct TextSettings +{ + TextSettings(): + fontFilename("fonts/arial.ttf"), + textColor(1.0f, 1.0f, 1.0f, 1.0f), + backdropType(osgText::Text::NONE), + backdropOffset(0.04f, 0.04f), + backdropColor(0.0f, 0.0f, 0.0f, 1.0f) + { + } + + void read(osg::ArgumentParser& arguments) + { + if (arguments.read("--outline")) backdropType = osgText::Text::OUTLINE; + if (arguments.read("--shadow")) backdropType = osgText::Text::DROP_SHADOW_BOTTOM_RIGHT; + + float offset; + if (arguments.read("--offset", offset)) backdropOffset.set(offset, offset); + + if (arguments.read("--text-color", textColor.r(), textColor.g(), textColor.b(), textColor.a())) {} + if (arguments.read("--bd-color", backdropColor.r(), backdropColor.g(), backdropColor.b(), backdropColor.a())) {} + } + + void setText(osgText::Text& text) + { + OSG_NOTICE<<"Settings::setText()"< font = osgText::readRefFontFile(fontfile); + osg::ref_ptr font = osgText::readRefFontFile(settings.fontFilename); + + settings.setText(*label); - label->setFont(font); label->setCharacterSize(size); label->setFontResolution(size, size); - label->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); label->setPosition(pos); label->setAlignment(osgText::Text::LEFT_BOTTOM); + // It seems to be important we do this last to get best results? label->setText(l); - textInfo(label); + + // textInfo(label); pos.y() += size + 10.0f; return label; } + + typedef std::list Sizes; int main(int argc, char** argv) @@ -101,6 +146,11 @@ int main(int argc, char** argv) viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); + osg::Vec4d backgroudColor = viewer.getCamera()->getClearColor(); + if (args.read("--bg-color", backgroudColor.r(), backgroudColor.g(), backgroudColor.b(), backgroudColor.a())) + { + viewer.getCamera()->setClearColor(backgroudColor); + } osg::ref_ptr root = new osg::Group; @@ -119,9 +169,10 @@ int main(int argc, char** argv) root = transform; } - std::string fontfile("arial.ttf"); + TextSettings settings; + settings.fontFilename = argv[1]; + settings.read(args); - fontfile = argv[1]; // Create the list of desired sizes. Sizes sizes; @@ -142,11 +193,18 @@ int main(int argc, char** argv) ss << *i << " 1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - geode->addDrawable(createLabel(ss.str(), fontfile, *i)); + geode->addDrawable(createLabel(ss.str(), settings, *i)); } root->addChild(geode); + std::string filename; + if (args.read("-o", filename)) + { + osgDB::writeNodeFile(*root, filename); + return 0; + } + viewer.setSceneData(root.get()); return viewer.run(); diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 53a5d3b1a..af9b4eccc 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -1131,6 +1131,8 @@ void Text::drawImplementationSinglePass(osg::State& state, const osg::Vec4& colo #if 1 if(_backdropType != NONE) { + OSG_NOTICE<<"Text::drawImplementationSinglePass() Drawing backdrop"<draw(state, usingVertexBufferObjects); } }