/* 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 #include #include extern int main_orig(int, char**); extern int main_test(int, char**); class Boundary { public: typedef std::pair Segment; typedef std::vector Segments; osg::ref_ptr _vertices; Segments _segments; Boundary(osg::Vec3Array* vertices, unsigned int start, unsigned int count) { _vertices = vertices; if ((*_vertices)[start]==(*_vertices)[start+count-1]) { // OSG_NOTICE<<"Boundary is a line loop"< 0.0f) { // OSG_NOTICE<<" computeBisectorNormal(a=["<(orig_geometry->getVertexArray()); osg::Geometry::PrimitiveSetList& orig_primitives = orig_geometry->getPrimitiveSetList(); osg::Geometry* new_geometry = new osg::Geometry; osg::Vec4Array* new_colours = new osg::Vec4Array; new_colours->push_back(osg::Vec4(1.0,1.0,0.0,1.0)); new_geometry->setColorArray(new_colours); new_geometry->setColorBinding(osg::Geometry::BIND_OVERALL); for(osg::Geometry::PrimitiveSetList::iterator itr = orig_primitives.begin(); itr != orig_primitives.end(); ++itr) { osg::DrawArrays* drawArray = dynamic_cast(itr->get()); if (drawArray && drawArray->getMode()==GL_POLYGON) { Boundary boundary(orig_vertices, drawArray->getFirst(), drawArray->getCount()); boundary.computeAllThickness(); boundary.removeAllSegmentsBelowThickness(thickness); boundary.addBoundaryToGeometry(new_geometry, thickness); } } return new_geometry; } 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); } std::string fontFile("arial.ttf"); while(arguments.read("-f",fontFile)) {} std::string word("This is a simple test"); while(arguments.read("--ascii")) { word.clear(); for(unsigned int c=' '; c<=127;++c) { word.push_back(c); } } while(arguments.read("-w",word)) {} osg::ref_ptr font = osgText::readFont3DFile(fontFile); if (!font) return 1; OSG_NOTICE<<"Read font "< group = new osg::Group; osg::Vec3 position; for(unsigned int i=0; i glyph = font->getGlyph(word[i]); if (!glyph) return 1; osg::ref_ptr transform = new osg::PositionAttitudeTransform; transform->setPosition(position); transform->setAttitude(osg::Quat(osg::inDegrees(90.0),osg::Vec3d(1.0,0.0,0.0))); position.x() += glyph->getHorizontalWidth(); osg::ref_ptr geode = new osg::Geode; osg::Vec3Array* vertices = glyph->getRawVertexArray(); osg::Geometry::PrimitiveSetList& primitives = glyph->getRawFacePrimitiveSetList(); osg::ref_ptr geometry = new osg::Geometry; geometry->setVertexArray(vertices); geometry->setPrimitiveSetList(primitives); osg::Vec4Array* colours = new osg::Vec4Array; colours->push_back(osg::Vec4(1.0,1.0,1.0,1.0)); geometry->setColorArray(colours); geometry->setColorBinding(osg::Geometry::BIND_OVERALL); osg::Geometry* bevel = computeThickness(geometry, thickness); if (bevel) geode->addDrawable(bevel); if (useTessellator) { if (geometry) { osgUtil::Tessellator ts; ts.setWindingType(osgUtil::Tessellator::TESS_WINDING_POSITIVE); ts.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); ts.retessellatePolygons(*geometry); } if (bevel) { osgUtil::Tessellator ts; ts.setWindingType(osgUtil::Tessellator::TESS_WINDING_POSITIVE); ts.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); ts.retessellatePolygons(*bevel); } } geode->addDrawable(geometry.get()); transform->addChild(geode.get()); group->addChild(transform.get()); } std::string filename; if (arguments.read("-o", filename)) osgDB::writeNodeFile(*group, filename); osgViewer::Viewer viewer(arguments); viewer.setSceneData(group.get()); viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); return viewer.run(); }