Changeset 11735
- Timestamp:
- 09/06/10 17:43:59 (21 months ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 10 modified
-
examples/osgtext3D/GlyphGeometry.cpp (modified) (5 diffs)
-
examples/osgtext3D/GlyphGeometry.h (modified) (1 diff)
-
examples/osgtext3D/TextNode.cpp (modified) (4 diffs)
-
examples/osgtext3D/osgtext3D.cpp (modified) (3 diffs)
-
include/osgText/Text3D (modified) (4 diffs)
-
src/osgPlugins/freetype/FreeTypeFont.cpp (modified) (16 diffs)
-
src/osgPlugins/freetype/FreeTypeFont.h (modified) (1 diff)
-
src/osgText/Font.cpp (modified) (2 diffs)
-
src/osgText/Text3D.cpp (modified) (2 diffs)
-
src/osgWrappers/serializers/osgText/Text3D.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgtext3D/GlyphGeometry.cpp
r11731 r11735 410 410 ///////////////////////////////////////////////////////////////////////////////////////// 411 411 // 412 // BevelProfile413 //414 BevelProfile::BevelProfile()415 {416 flatBevel();417 }418 419 void BevelProfile::flatBevel(float width)420 {421 _vertices.clear();422 423 if (width>0.5f) width = 0.5f;424 425 _vertices.push_back(osg::Vec2(0.0f,0.0f));426 427 _vertices.push_back(osg::Vec2(width,1.0f));428 429 if (width<0.5f) _vertices.push_back(osg::Vec2(1-width,1.0f));430 431 _vertices.push_back(osg::Vec2(1.0f,0.0f));432 }433 434 void BevelProfile::roundedBevel(float width, unsigned int numSteps)435 {436 _vertices.clear();437 438 if (width>0.5f) width = 0.5f;439 440 unsigned int i = 0;441 for(; i<=numSteps; ++i)442 {443 float angle = float(osg::PI)*0.5f*(float(i)/float(numSteps));444 _vertices.push_back( osg::Vec2((1.0f-cosf(angle))*width, sinf(angle)) );445 }446 447 // start the second half one into the curve if the width is half way across448 i = width<0.5f ? 0 : 1;449 for(; i<=numSteps; ++i)450 {451 float angle = float(osg::PI)*0.5f*(float(numSteps-i)/float(numSteps));452 _vertices.push_back( osg::Vec2(1.0-(1.0f-cosf(angle))*width, sin(angle)) );453 }454 }455 456 void BevelProfile::roundedBevel2(float width, unsigned int numSteps)457 {458 _vertices.clear();459 460 if (width>0.5f) width = 0.5f;461 462 float h = 0.1f;463 float r = 1.0f-h;464 465 _vertices.push_back(osg::Vec2(0.0,0.0));466 467 unsigned int i = 0;468 for(; i<=numSteps; ++i)469 {470 float angle = float(osg::PI)*0.5f*(float(i)/float(numSteps));471 _vertices.push_back( osg::Vec2((1.0f-cosf(angle))*width, h + sinf(angle)*r) );472 }473 474 // start the second half one into the curve if the width is half way across475 i = width<0.5f ? 0 : 1;476 for(; i<=numSteps; ++i)477 {478 float angle = float(osg::PI)*0.5f*(float(numSteps-i)/float(numSteps));479 _vertices.push_back( osg::Vec2(1.0-(1.0f-cosf(angle))*width, h + sin(angle)*r) );480 }481 482 _vertices.push_back(osg::Vec2(1.0,0.0));483 484 }485 486 void BevelProfile::print(std::ostream& fout)487 {488 OSG_NOTICE<<"print bevel"<<std::endl;489 for(Vertices::iterator itr = _vertices.begin();490 itr != _vertices.end();491 ++itr)492 {493 OSG_NOTICE<<" "<<*itr<<std::endl;494 }495 }496 497 /////////////////////////////////////////////////////////////////////////////////////////498 //499 412 // computeGlyphGeometry 500 413 // … … 602 515 // computeTextGeometry 603 516 // 604 osg::Geometry* computeTextGeometry(osg::Geometry* glyphGeometry, BevelProfile& profile, float width)517 osg::Geometry* computeTextGeometry(osg::Geometry* glyphGeometry, const osgText::Bevel& profile, float width) 605 518 { 606 519 osg::Vec3Array* orig_vertices = dynamic_cast<osg::Vec3Array*>(glyphGeometry->getVertexArray()); … … 699 612 unsigned int no_vertices_on_boundary = bevel->size()/2; 700 613 701 osgText::BevelProfile::Vertices& profileVertices = profile.getVertices();614 const osgText::Bevel::Vertices& profileVertices = profile.getVertices(); 702 615 unsigned int no_vertices_on_bevel = profileVertices.size(); 703 616 … … 782 695 // computeShellGeometry 783 696 // 784 osg::Geometry* computeShellGeometry(osg::Geometry* glyphGeometry, BevelProfile& profile, float width)697 osg::Geometry* computeShellGeometry(osg::Geometry* glyphGeometry, const osgText::Bevel& profile, float width) 785 698 { 786 699 osg::Vec3Array* orig_vertices = dynamic_cast<osg::Vec3Array*>(glyphGeometry->getVertexArray()); … … 925 838 unsigned int no_vertices_on_boundary = bevel->size()/2; 926 839 927 osgText::BevelProfile::Vertices& profileVertices = profile.getVertices();840 const osgText::Bevel::Vertices& profileVertices = profile.getVertices(); 928 841 unsigned int no_vertices_on_bevel = profileVertices.size(); 929 842 -
OpenSceneGraph/trunk/examples/osgtext3D/GlyphGeometry.h
r11731 r11735 16 16 17 17 #include <osgText/Font3D> 18 #include "TextNode.h" 18 19 19 20 namespace osgText 20 21 { 21 22 22 class BevelProfile23 {24 public:25 26 typedef std::vector<osg::Vec2> Vertices;27 28 BevelProfile();29 30 void flatBevel(float width=0.25f);31 32 void roundedBevel(float width=0.5f, unsigned int numSteps=10);33 34 void roundedBevel2(float width=0.5f, unsigned int numSteps=10);35 36 void print(std::ostream& fout);37 38 Vertices& getVertices() { return _vertices; }39 40 protected:41 42 Vertices _vertices;43 };44 45 23 extern osg::Geometry* computeGlyphGeometry(osgText::Glyph3D* glyph, float bevelThickness, float shellThickness); 46 24 47 extern osg::Geometry* computeTextGeometry(osg::Geometry* glyphGeometry, BevelProfile& profile, float width);25 extern osg::Geometry* computeTextGeometry(osg::Geometry* glyphGeometry, const Bevel& profile, float width); 48 26 49 extern osg::Geometry* computeShellGeometry(osg::Geometry* glyphGeometry, BevelProfile& profile, float width);27 extern osg::Geometry* computeShellGeometry(osg::Geometry* glyphGeometry, const Bevel& profile, float width); 50 28 51 29 } -
OpenSceneGraph/trunk/examples/osgtext3D/TextNode.cpp
r11734 r11735 29 29 Bevel::Bevel() 30 30 { 31 _thickness = 0. 1f;31 _thickness = 0.02f; 32 32 flatBevel(); 33 33 } … … 192 192 if (style) 193 193 { 194 size.y() = characterSize * style->getWidthRatio();195 size.z() = characterSize * style->getThicknessRatio();194 size.y() = characterSize; 195 size.z() = characterSize; 196 196 } 197 197 … … 243 243 if (glyph) 244 244 { 245 technique->addCharacter(pos, size, glyph, style); 246 pos += osg::Vec3(size.x()*(glyph->getHorizontalAdvance()*characterWidthScale), 0.0f ,0.0f); 245 osg::Vec3 local_scale( size ); 246 local_scale *= (1.0f/font->getScale()); 247 248 technique->addCharacter(pos, local_scale, glyph, style); 249 pos += osg::Vec3(size.x()*(glyph->getHorizontalWidth()/font->getScale()), 0.0f ,0.0f); 247 250 } 248 251 } … … 302 305 OSG_NOTICE<<"TextTechnique::addCharacter 3D("<<position<<", "<<size<<", "<<glyph<<", "<<style<<")"<<std::endl; 303 306 304 double scale = size.x() / glyph->getVerticalHeight();305 306 307 osg::ref_ptr<osg::PositionAttitudeTransform> transform = new osg::PositionAttitudeTransform; 307 308 transform->setPosition(position); 308 309 transform->setAttitude(osg::Quat(osg::inDegrees(90.0),osg::Vec3d(1.0,0.0,0.0))); 309 transform->setScale( osg::Vec3d(scale, scale, scale));310 transform->setScale(size); 310 311 311 312 osg::ref_ptr<osg::Geode> geode = new osg::Geode; 312 313 313 bool outline = false; 314 float thickness = 5; 315 float width = 10; 316 BevelProfile profile; 314 const Bevel* bevel = style ? style->getBevel() : 0; 315 bool outline = style ? style->getOutlineRatio()>0.0f : false; 316 float width = style->getThicknessRatio(); 317 317 float creaseAngle = 30.0f; 318 318 bool smooth = true; 319 319 320 osg::ref_ptr<osg::Geometry> glyphGeometry = osgText::computeGlyphGeometry(glyph, thickness, width); 321 osg::ref_ptr<osg::Geometry> textGeometry = osgText::computeTextGeometry(glyphGeometry.get(), profile, width); 322 osg::ref_ptr<osg::Geometry> shellGeometry = outline ? osgText::computeShellGeometry(glyphGeometry.get(), profile, width) : 0; 323 if (textGeometry.valid()) geode->addDrawable(textGeometry.get()); 324 if (shellGeometry.valid()) geode->addDrawable(shellGeometry.get()); 325 326 // create the normals 327 if (smooth && textGeometry.valid()) 328 { 329 osgUtil::SmoothingVisitor::smooth(*textGeometry, osg::DegreesToRadians(creaseAngle)); 320 if (bevel) 321 { 322 float thickness = bevel->getBevelThickness(); 323 324 osg::ref_ptr<osg::Geometry> glyphGeometry = osgText::computeGlyphGeometry(glyph, thickness, width); 325 osg::ref_ptr<osg::Geometry> textGeometry = osgText::computeTextGeometry(glyphGeometry.get(), *bevel, width); 326 osg::ref_ptr<osg::Geometry> shellGeometry = outline ? osgText::computeShellGeometry(glyphGeometry.get(), *bevel, width) : 0; 327 if (textGeometry.valid()) geode->addDrawable(textGeometry.get()); 328 if (shellGeometry.valid()) geode->addDrawable(shellGeometry.get()); 329 330 // create the normals 331 if (smooth && textGeometry.valid()) 332 { 333 osgUtil::SmoothingVisitor::smooth(*textGeometry, osg::DegreesToRadians(creaseAngle)); 334 } 335 } 336 else 337 { 330 338 } 331 339 -
OpenSceneGraph/trunk/examples/osgtext3D/osgtext3D.cpp
r11734 r11735 75 75 OSG_NOTICE<<"creaseAngle="<<creaseAngle<<std::endl; 76 76 77 osgText::Bevel Profileprofile;77 osgText::Bevel profile; 78 78 float ratio = 0.5; 79 79 while(arguments.read("--rounded",ratio)) { profile.roundedBevel(ratio); } … … 170 170 osg::ref_ptr<osgText::Style> style = new osgText::Style; 171 171 172 float thickness = 0. 0f;172 float thickness = 0.1f; 173 173 while(arguments.read("--thickness",thickness)) {} 174 174 style->setThicknessRatio(thickness); 175 176 // set up any bevel if required 177 float r; 178 osg::ref_ptr<osgText::Bevel> bevel; 179 while(arguments.read("--rounded",r)) { bevel = new osgText::Bevel; bevel->roundedBevel2(r); } 180 while(arguments.read("--rounded")) { bevel = new osgText::Bevel; bevel->roundedBevel2(0.25); } 181 while(arguments.read("--flat",r)) { bevel = new osgText::Bevel; bevel->flatBevel(r); } 182 while(arguments.read("--flat")) { bevel = new osgText::Bevel; bevel->flatBevel(0.25); } 183 while(arguments.read("--bevel-thickness",r)) { if (bevel.valid()) bevel->setBevelThickness(r); } 184 185 style->setBevel(bevel); 175 186 176 187 osgText::TextNode* text = new osgText::TextNode; … … 181 192 text->update(); 182 193 194 viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); 195 viewer.addEventHandler(new osgViewer::StatsHandler); 183 196 viewer.setSceneData(text); 184 197 -
OpenSceneGraph/trunk/include/osgText/Text3D
r11732 r11735 17 17 18 18 #include <osgText/TextBase> 19 #include <osgText/Font3D> 20 19 #include <osgText/Font> 21 20 22 21 namespace osgText { … … 76 75 /** Set the Font to use to render the text. 77 76 * setFont(0) sets the use of the default font.*/ 78 inline void setFont(Font3D* font=0) { setFont(osg::ref_ptr<Font3D>(font)); }; 79 80 /** Set the Font to use to render the text.*/ 81 void setFont(osg::ref_ptr<Font3D> font); 82 77 void setFont(Font* font); 83 78 84 79 /** Set the font, loaded from the specified front file, to use to render the text, … … 88 83 89 84 /** Get the font. Return 0 if default is being used.*/ 90 const Font 3D* getFont() const { return _font.get(); }85 const Font* getFont() const { return _font.get(); } 91 86 92 87 … … 157 152 TextRenderInfo _textRenderInfo; 158 153 159 osg::ref_ptr<Font 3D> _font;154 osg::ref_ptr<Font> _font; 160 155 161 156 float _characterDepth; -
OpenSceneGraph/trunk/src/osgPlugins/freetype/FreeTypeFont.cpp
r11732 r11735 36 36 _maxX(-FLT_MAX), 37 37 _minX(FLT_MAX), 38 _minY(FLT_MAX) 38 _minY(FLT_MAX), 39 _coord_scale(1.0/64.0) 39 40 { 40 41 } … … 56 57 } 57 58 58 void addVertex(const osg::Vec3& pos) 59 { 59 void addVertex(osg::Vec3 pos) 60 { 61 _previous = pos; 62 63 pos *= _coord_scale; 64 60 65 if (!_verts->empty() && _verts->back()==pos) 61 66 { … … 85 90 void conicTo(const osg::Vec2& control, const osg::Vec2& pos) 86 91 { 87 osg::Vec3 p0 = _ verts->back();92 osg::Vec3 p0 = _previous; 88 93 osg::Vec3 p1 = osg::Vec3(control.x(),control.y(),0); 89 94 osg::Vec3 p2 = osg::Vec3(pos.x(),pos.y(),0); … … 104 109 void cubicTo(const osg::Vec2& control1, const osg::Vec2& control2, const osg::Vec2& pos) 105 110 { 106 osg::Vec3 p0 = _ verts->back();111 osg::Vec3 p0 = _previous; 107 112 osg::Vec3 p1 = osg::Vec3(control1.x(),control1.y(),0); 108 113 osg::Vec3 p2 = osg::Vec3(control2.x(),control2.y(),0); … … 137 142 osg::ref_ptr<osg::Vec3Array> _verts; 138 143 osg::ref_ptr<osg::Geometry> _geometry; 144 osg::Vec3 _previous; 139 145 int _idx; 140 146 int _numSteps; … … 143 149 double _minX; 144 150 double _minY; 151 double _coord_scale; 152 145 153 }; 146 154 147 155 148 #define FT_NUM(x) (x/64.0)149 156 int moveTo( const FT_Vector* to, void* user ) 150 157 { 151 158 Char3DInfo* char3d = (Char3DInfo*)user; 152 char3d->moveTo( osg::Vec2( FT_NUM(to->x),FT_NUM(to->y)) );159 char3d->moveTo( osg::Vec2(to->x,to->y) ); 153 160 return 0; 154 161 } … … 156 163 { 157 164 Char3DInfo* char3d = (Char3DInfo*)user; 158 char3d->lineTo( osg::Vec2( FT_NUM(to->x),FT_NUM(to->y)) );165 char3d->lineTo( osg::Vec2(to->x,to->y) ); 159 166 return 0; 160 167 } … … 162 169 { 163 170 Char3DInfo* char3d = (Char3DInfo*)user; 164 char3d->conicTo( osg::Vec2( FT_NUM(control->x),FT_NUM(control->y)), osg::Vec2(FT_NUM(to->x),FT_NUM(to->y)) );171 char3d->conicTo( osg::Vec2(control->x,control->y), osg::Vec2(to->x,to->y) ); 165 172 return 0; 166 173 } … … 169 176 Char3DInfo* char3d = (Char3DInfo*)user; 170 177 char3d->cubicTo( 171 osg::Vec2( FT_NUM(control1->x),FT_NUM(control1->y)),172 osg::Vec2( FT_NUM(control2->x),FT_NUM(control2->y)),173 osg::Vec2( FT_NUM(to->x),FT_NUM(to->y)) );178 osg::Vec2(control1->x,control1->y), 179 osg::Vec2(control2->x,control2->y), 180 osg::Vec2(to->x,to->y) ); 174 181 return 0; 175 182 } 176 #undef FT_NUM177 183 178 184 } … … 184 190 _face(face), 185 191 _flags(flags), 186 _scale(1.0f) 192 _scale(1.0f), 193 _freetype_scale(1.0f) 187 194 { 188 195 init(); … … 195 202 _face(face), 196 203 _flags(flags), 197 _scale(1.0f) 204 _scale(1.0f), 205 _freetype_scale(1.0f) 198 206 { 199 207 init(); … … 280 288 // double width = (xmax - xmin)/64.0; 281 289 282 _scale = 1.0/height; 290 #if 1 291 _freetype_scale = 1.0f/height; 292 _scale = 1.0f; 293 #else 294 _freetype_scale = 1.0f; 295 _scale = 1.0f/height; 296 #endif 283 297 } 284 298 } … … 408 422 409 423 410 FT_Glyph_Metrics* metrics = &(glyphslot->metrics); 411 412 glyph->setHorizontalBearing(osg::Vec2((float)metrics->horiBearingX/64.0f,(float)(metrics->horiBearingY-metrics->height)/64.0f)); // bottom left. 413 glyph->setHorizontalAdvance((float)metrics->horiAdvance/64.0f); 414 glyph->setVerticalBearing(osg::Vec2((float)metrics->vertBearingX/64.0f,(float)(metrics->vertBearingY-metrics->height)/64.0f)); // top middle. 415 glyph->setVerticalAdvance((float)metrics->vertAdvance/64.0f); 424 FT_Glyph_Metrics* metrics = &(_face->glyph->metrics); 425 426 float coord_scale = _freetype_scale/64.0f; 427 428 glyph->setHorizontalBearing(osg::Vec2((float)metrics->horiBearingX * coord_scale,(float)(metrics->horiBearingY-metrics->height) * coord_scale)); // bottom left. 429 glyph->setHorizontalAdvance((float)metrics->horiAdvance * coord_scale); 430 glyph->setVerticalBearing(osg::Vec2((float)metrics->vertBearingX * coord_scale,(float)(metrics->vertBearingY-metrics->height) * coord_scale)); // top middle. 431 glyph->setVerticalAdvance((float)metrics->vertAdvance * coord_scale); 416 432 417 433 // cout << " in getGlyph() implementation="<<this<<" "<<_filename<<" facade="<<_facade<<endl; … … 452 468 } 453 469 470 float coord_scale = _freetype_scale/64.0f; 471 454 472 // ** init FreeType to describe the glyph 455 473 FreeType::Char3DInfo char3d(_facade->getNumberCurveSamples()); 474 char3d._coord_scale = coord_scale; 456 475 457 476 FT_Outline outline = _face->glyph->outline; … … 597 616 FT_Glyph_Metrics* metrics = &(_face->glyph->metrics); 598 617 599 glyph3D->setHorizontalBearing(osg::Vec2((float)metrics->horiBearingX/64.0f,(float)(metrics->horiBearingY-metrics->height)/64.0f)); // bottom left. 600 glyph3D->setHorizontalAdvance((float)metrics->horiAdvance/64.0f); 601 glyph3D->setVerticalBearing(osg::Vec2((float)metrics->vertBearingX/64.0f,(float)(metrics->vertBearingY-metrics->height)/64.0f)); // top middle. 602 glyph3D->setVerticalAdvance((float)metrics->vertAdvance/64.0f); 603 604 glyph3D->setWidth((float)metrics->width / 64.0f); 605 glyph3D->setHeight((float)metrics->height / 64.0f); 606 618 glyph3D->setHorizontalBearing(osg::Vec2((float)metrics->horiBearingX * coord_scale,(float)(metrics->horiBearingY-metrics->height) * coord_scale)); // bottom left. 619 glyph3D->setHorizontalAdvance((float)metrics->horiAdvance * coord_scale); 620 glyph3D->setVerticalBearing(osg::Vec2((float)metrics->vertBearingX * coord_scale,(float)(metrics->vertBearingY-metrics->height) * coord_scale)); // top middle. 621 glyph3D->setVerticalAdvance((float)metrics->vertAdvance * coord_scale); 622 623 glyph3D->setWidth((float)metrics->width * coord_scale); 624 glyph3D->setHeight((float)metrics->height * coord_scale); 607 625 608 626 FT_BBox ftbb; … … 614 632 long ymax = ft_ceiling( ftbb.yMax ); 615 633 616 osg::BoundingBox bb(xmin / 64.0f, ymin / 64.0f, 0.0f, xmax / 64.0f, ymax / 64.0f, 0.0f);634 osg::BoundingBox bb(xmin * coord_scale, ymin * coord_scale, 0.0f, xmax * coord_scale, ymax * coord_scale, 0.0f); 617 635 618 636 glyph3D->setBoundingBox(bb); -
OpenSceneGraph/trunk/src/osgPlugins/freetype/FreeTypeFont.h
r11732 r11735 59 59 unsigned int _flags; 60 60 float _scale; 61 float _freetype_scale; 61 62 }; 62 63 -
OpenSceneGraph/trunk/src/osgText/Font.cpp
r11732 r11735 343 343 Glyph* Font::getGlyph(const FontResolution& fontRes, unsigned int charcode) 344 344 { 345 OSG_NOTICE<<"Font::getGlyph("<<charcode<<")"<<std::endl; 346 345 347 { 346 348 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_glyphMapMutex); … … 365 367 Glyph3D* Font::getGlyph3D(unsigned int charcode) 366 368 { 369 OSG_NOTICE<<"Font::getGlyph3D("<<charcode<<")"<<std::endl; 370 367 371 { 368 372 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_glyphMapMutex); -
OpenSceneGraph/trunk/src/osgText/Text3D.cpp
r11732 r11735 103 103 } 104 104 105 void Text3D::setFont( osg::ref_ptr<Font3D>font)105 void Text3D::setFont(Font* font) 106 106 { 107 107 _font = font; … … 112 112 void Text3D::setFont(const std::string & fontfile) 113 113 { 114 setFont(readRefFont 3DFile(fontfile));114 setFont(readRefFontFile(fontfile)); 115 115 } 116 116 -
OpenSceneGraph/trunk/src/osgWrappers/serializers/osgText/Text3D.cpp
r11028 r11735 12 12 { 13 13 std::string fontName; is.readWrappedString( fontName ); 14 text.setFont( osgText::readFont 3DFile(fontName) );14 text.setFont( osgText::readFontFile(fontName) ); 15 15 return true; 16 16 }
