/* 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 osg::Group* createHUDText() { osg::Group* rootNode = new osg::Group; osg::ref_ptr font = osgText::readRefFontFile("fonts/arial.ttf"); osg::Geode* geode = new osg::Geode; rootNode->addChild(geode); osg::Vec4 layoutColor(1.0f,1.0f,0.0f,1.0f); float layoutCharacterSize = 24.0f; { osgText::Text* text = new osgText::Text; text->setFont(font); text->setColor(layoutColor); text->setCharacterSize(layoutCharacterSize); text->setCharacterSizeMode(osgText::TextBase::SCREEN_COORDS); text->setAxisAlignment(osgText::TextBase::SCREEN); text->setPosition(osg::Vec3(0.125,0.1,0.0f)); text->setText("Horizontal Text"); geode->addDrawable(text); } { osgText::Text* text = new osgText::Text; text->setFont(font); text->setColor(layoutColor); text->setCharacterSize(layoutCharacterSize); text->setCharacterSizeMode(osgText::TextBase::SCREEN_COORDS); text->setAxisAlignment(osgText::TextBase::SCREEN); text->setPosition(osg::Vec3(0.1, 0.1, 0.0f)); text->setRotation(osg::Quat(osg::PI_2, osg::Vec3(0, 0, 1))); text->setText("Vertical Text"); geode->addDrawable(text); } 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, 300); // make sure the root node is group so we can add extra nodes to it. osg::Group* group = new osg::Group; // create the hud. osg::Camera* camera = new osg::Camera; camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera->setProjectionMatrixAsOrtho2D(0, 1, 0, 1); camera->setProjectionResizePolicy(osg::Camera::FIXED); camera->setViewMatrix(osg::Matrix::identity()); camera->setClearMask(GL_DEPTH_BUFFER_BIT); camera->addChild(createHUDText()); camera->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); group->addChild(camera); // set the scene to render viewer.setSceneData(group); viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.run(); return 0; }