/* 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. */ #include #include #include #include #include #include #include #include #include // create text which sits in 3D space such as would be inserted into a normal model osg::Group* create3DText(const osg::Vec3& center) { osg::Geode* geode = new osg::Geode; osgText::Text* text5 = new osgText::Text; text5->setFont("fonts/times.ttf"); text5->setCharacterSize(32.0f); // medium text5->setPosition(center - osg::Vec3(0.0, 0.0, 0.2)); text5->setAxisAlignment(osgText::Text::SCREEN); text5->setCharacterSizeMode(osgText::Text::SCREEN_COORDS); text5->setDrawMode(osgText::Text::TEXT | osgText::Text::BOUNDINGBOX); text5->setText("Resize skinny vs tall and see font size difference"); geode->addDrawable(text5); osg::Group* rootNode = new osg::Group; rootNode->addChild(geode); return rootNode; } int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); // construct the viewer. osgViewer::Viewer viewer(arguments); viewer.setUpViewInWindow(100, 100, 800, 600); // prepare scene. osg::Vec3 center(0.0f, 0.0f, 0.0f); // make sure the root node is group so we can add extra nodes to it. osg::Group* group = new osg::Group; group->addChild(create3DText(center)); // set the scene to render viewer.setSceneData(group); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); int width = 800; int height = 600; if (arguments.read("--size1")) ; // noop else if (arguments.read("--size2")) height = 100; else if (arguments.read("--size3")) width = 100; viewer.setUpViewInWindow(100, 100, width, height); viewer.run(); return 0; }