Changeset 9881
- Timestamp:
- 03/10/09 11:56:00 (4 years ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 7 modified
-
include/osgText/Font3D (modified) (16 diffs)
-
include/osgText/Text3D (modified) (14 diffs)
-
src/osgDB/Registry.cpp (modified) (1 diff)
-
src/osgPlugins/freetype/FreeTypeFont3D.cpp (modified) (18 diffs)
-
src/osgPlugins/freetype/ReaderWriterFreeType.cpp (modified) (5 diffs)
-
src/osgText/Font3D.cpp (modified) (12 diffs)
-
src/osgText/Text3D.cpp (modified) (47 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgText/Font3D
r7874 r9881 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 32 32 33 33 /** Read a font from specified file. The filename may contain a path. 34 * It will search for the font file in the following places in this order: 34 * It will search for the font file in the following places in this order: 35 35 * - In the current directory 36 36 * - All paths defined in OSG_FILE_PATH or OSGFILEPATH environment variable … … 46 46 * - Other OS: In /usr/share/fonts/ttf/western 47 47 * - Other OS: In /usr/share/fonts/ttf/decoratives 48 * 48 * 49 49 * If the given file could not be found, the path part will be stripped and 50 50 * the file will be searched again in the OS specific directories. … … 68 68 // declare the interface to a font. 69 69 public: 70 70 71 71 // forward declare nested classes. 72 72 class Glyph3D; … … 93 93 /** Get a Glyph for specified charcode, and the font size nearest to the current font size hint.*/ 94 94 virtual Glyph3D* getGlyph(unsigned int charcode); 95 95 96 96 /** Return true if this font provides vertical alignments and spacing or glyphs.*/ 97 97 virtual bool hasVertical() const; … … 99 99 /** Return the scale to apply on the glyph to have a charactere size equal to 1 */ 100 100 virtual float getScale() const { return _implementation->getScale(); }; 101 101 102 102 // make Text a friend to allow it add and remove its entry in the Font's _textList. 103 103 friend class Font3DImplementation; … … 110 110 /** Set whether to use a mutex to ensure ref() and unref() */ 111 111 virtual void setThreadSafeRefUnref(bool threadSafe); 112 112 113 113 typedef OpenThreads::Mutex Font3DMutex; 114 114 … … 116 116 117 117 virtual ~Font3D(); 118 118 119 119 // void addGlyph(unsigned int width, unsigned int height, unsigned int charcode, Glyph* glyph); 120 120 void addGlyph(unsigned int charcode, Glyph3D* glyph); 121 121 122 122 // current active size of font 123 123 unsigned int _depth; … … 128 128 129 129 typedef std::map<char, osg::ref_ptr<Glyph3D> > Glyph3DMap; 130 Glyph3DMap _glyph3DMap; 131 130 Glyph3DMap _glyph3DMap; 131 132 132 osg::ref_ptr<Font3DImplementation> _implementation; 133 133 134 134 135 135 // declare the nested classes. 136 136 public: … … 139 139 { 140 140 public: 141 141 142 142 Font3DImplementation(): 143 143 osg::Referenced(true), 144 144 _facade(0) {} 145 145 146 146 virtual std::string getFileName() const = 0; 147 147 … … 154 154 /** Return true if this font provides vertical alignments and spacing or glyphs.*/ 155 155 virtual bool hasVertical() const = 0; 156 156 157 157 virtual float getScale() const = 0; 158 158 159 159 void setFontWidth(unsigned int width) { _facade->_width = width; } 160 160 161 161 void setFontHeight(unsigned int height) { _facade->_height = height; } 162 162 163 163 void setFontDepth(unsigned int depth) { _facade->_depth = depth; } 164 164 165 165 // void addGlyph(unsigned int width, unsigned int height, unsigned int charcode, Glyph3D* glyph) 166 166 // { 167 167 // _facade->addGlyph(width, height, charcode, glyph); 168 168 // } 169 // 169 // 170 170 // void addGlyph(unsigned int charcode, Glyph3D* glyph) 171 171 // { … … 182 182 Glyph3D(unsigned int glyphCode): 183 183 osg::Referenced(true), 184 _glyphCode(glyphCode), 184 _glyphCode(glyphCode), 185 185 _horizontalBearing(0,0), 186 186 _horizontalAdvance(0), … … 188 188 _verticalAdvance(0) 189 189 {} 190 190 191 191 192 192 /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ 193 193 // virtual int compare(const osg::StateAttribute& rhs) const; 194 // 194 // 195 195 // virtual void apply(osg::State& state) const; 196 196 197 198 197 198 199 199 unsigned int getGlyphCode() const { return _glyphCode; } 200 200 201 201 void setHorizontalBearing(const osg::Vec2& bearing) { _horizontalBearing=bearing; } 202 202 const osg::Vec2 & getHorizontalBearing() const { return _horizontalBearing; } 203 203 204 204 void setHorizontalAdvance(float advance) { _horizontalAdvance=advance; } 205 205 float getHorizontalAdvance() const { return _horizontalAdvance; } … … 210 210 void setVerticalAdvance(float advance) { _verticalAdvance=advance; } 211 211 float getVerticalAdvance() const { return _verticalAdvance; } 212 212 213 213 void setBoundingBox(osg::BoundingBox & bb) { _bb=bb; } 214 214 const osg::BoundingBox & getBoundingBox() const { return _bb; } 215 216 215 216 217 217 /** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/ 218 218 virtual void setThreadSafeRefUnref(bool threadSafe); 219 219 220 220 221 221 /** Get the PrimitiveSetList for the front face. */ 222 222 osg::Geometry::PrimitiveSetList & getFrontPrimitiveSetList() { return _frontPrimitiveSetList; } … … 225 225 /** Get et the PrimitiveSetList for the back face. */ 226 226 osg::Geometry::PrimitiveSetList & getBackPrimitiveSetList() { return _backPrimitiveSetList; } 227 227 228 228 /** Set the VertexArray of the glyph. */ 229 229 void setVertexArray(osg::Vec3Array * va) { _vertexArray = va; } 230 230 /** Get the VertexArray of the glyph. */ 231 231 osg::Vec3Array * getVertexArray() { return _vertexArray.get(); } 232 /** Set the VertexArray of the glyph. */ 233 void setNormalArray(osg::Vec3Array * na) { _normalArray = na; } 232 234 /** Get the NormalArray for the wall face. */ 233 235 osg::Vec3Array * getNormalArray() { return _normalArray.get(); } 234 236 235 237 float getHorizontalWidth() { return (-_horizontalBearing.x() + _horizontalAdvance); } 236 238 float getHorizontalHeight() { return (-_horizontalBearing.y() + _bb.yMax()); } 237 239 float getVerticalWidth() { return (-_verticalBearing.x() + _bb.xMax()); } 238 240 float getVerticalHeight() { return (-_verticalBearing.y() + _verticalAdvance); } 239 241 240 242 void setWidth(float width) { _width = width; } 241 243 float getWidth() { return _width; } 242 244 243 245 void setHeight(float height) { _height = height; } 244 246 float getHeight() { return _height; } 245 247 246 248 protected: 247 249 248 250 virtual ~Glyph3D() {} 249 251 … … 256 258 float _verticalAdvance; 257 259 258 osg::BoundingBox _bb; 260 osg::BoundingBox _bb; 259 261 // osg::Vec2 _advance; 260 262 261 263 float _width; 262 264 float _height; 263 264 265 266 265 267 osg::ref_ptr<osg::Vec3Array> _vertexArray; 266 268 osg::ref_ptr<osg::Vec3Array> _normalArray; 267 269 268 270 osg::Geometry::PrimitiveSetList _frontPrimitiveSetList; 269 271 osg::Geometry::PrimitiveSetList _wallPrimitiveSetList; 270 272 osg::Geometry::PrimitiveSetList _backPrimitiveSetList; 271 272 273 274 273 275 }; 274 276 -
OpenSceneGraph/trunk/include/osgText/Text3D
r8441 r9881 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 31 31 * all wall face with the wall StateSet 32 32 * all back face with the back StateSet (back face of the character, no the OpenGL back face) 33 * 33 * 34 34 * PER_GLYPH : render all Charactere with the default StateSet 35 35 */ … … 39 39 PER_GLYPH 40 40 }; 41 41 42 42 Text3D(); 43 43 Text3D(const Text3D& text,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); … … 49 49 /** Set the Charactere Depth of text. */ 50 50 void setCharacterDepth(float characterDepth) { _characterDepth = characterDepth; computeGlyphRepresentation(); } 51 51 52 52 /** Get the render mode used to render the text. */ 53 53 RenderMode getRenderMode() const { return _renderMode; } … … 58 58 // osg::StateSet * getWallStateSet() { return _wallStateSet.get(); } 59 59 // /** Get or create the wall StateSet */ 60 // osg::StateSet * getOrCreateWallStateSet() 61 // { 62 // if (_wallStateSet.valid() == false) _wallStateSet = new osg::StateSet; 63 // return _wallStateSet.get(); 60 // osg::StateSet * getOrCreateWallStateSet() 61 // { 62 // if (_wallStateSet.valid() == false) _wallStateSet = new osg::StateSet; 63 // return _wallStateSet.get(); 64 64 // } 65 65 // /** Set the wall StateSet */ … … 72 72 // /** Set the back StateSet */ 73 73 // void setBackStateSet(osg::StateSet * backStateSet) { _backStateSet = backStateSet; } 74 // 75 76 /** Set the Font to use to render the text. 74 // 75 76 /** Set the Font to use to render the text. 77 77 * setFont(0) sets the use of the default font.*/ 78 78 inline void setFont(Font3D* font=0) { setFont(osg::ref_ptr<Font3D>(font)); }; … … 87 87 void setFont(const std::string& fontfile); 88 88 89 /** Get the font. Return 0 if default is being used.*/ 89 /** Get the font. Return 0 if default is being used.*/ 90 90 const Font3D* getFont() const { return _font.get(); } 91 91 92 93 94 92 93 94 95 95 /** Draw the text.*/ 96 96 virtual void drawImplementation(osg::RenderInfo& renderInfo) const; … … 103 103 104 104 /** accept an ConstAttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/ 105 //virtual void accept(osg::Drawable::ConstAttributeFunctor& af) const;105 virtual void accept(osg::Drawable::ConstAttributeFunctor& af) const; 106 106 107 107 /** return true, osgText::Text does support accept(PrimitiveFunctor&) .*/ … … 109 109 110 110 /** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/ 111 //virtual void accept(osg::PrimitiveFunctor& pf) const;111 virtual void accept(osg::PrimitiveFunctor& pf) const; 112 112 113 113 … … 123 123 virtual void releaseGLObjects(osg::State* state=0) const; 124 124 125 // // make Font a friend to allow it set the _font to 0 if the font is 125 // // make Font a friend to allow it set the _font to 0 if the font is 126 126 // // forcefully unloaded. 127 127 friend class Font3D; … … 132 132 protected: 133 133 134 virtual ~Text3D() {} 135 134 virtual ~Text3D() {} 135 136 136 void renderPerGlyph(osg::State & state) const; 137 137 void renderPerFace(osg::State & state) const; … … 141 141 void computeGlyphRepresentation(); 142 142 void computePositions(unsigned int contextID) const; 143 143 144 144 // ** glyph and other information to render the glyph 145 145 struct GlyphRenderInfo … … 147 147 GlyphRenderInfo(Font3D::Glyph3D * glyph, osg::Vec3 & pos) : 148 148 _glyph(glyph), _position(pos) {} 149 149 150 150 osg::ref_ptr<Font3D::Glyph3D> _glyph; 151 151 osg::Vec3 _position; 152 152 }; 153 153 154 154 typedef std::vector<GlyphRenderInfo> LineRenderInfo; 155 typedef std::vector<LineRenderInfo> TextRenderInfo; 156 155 typedef std::vector<LineRenderInfo> TextRenderInfo; 156 157 157 TextRenderInfo _textRenderInfo; 158 158 … … 160 160 161 161 float _characterDepth; 162 162 163 163 RenderMode _renderMode; 164 164 165 165 osg::ref_ptr<osg::StateSet> _wallStateSet; 166 166 osg::ref_ptr<osg::StateSet> _backStateSet; -
OpenSceneGraph/trunk/src/osgDB/Registry.cpp
r9880 r9881 319 319 addFileExtensionAlias("cef", "freetype"); // OpenType 320 320 addFileExtensionAlias("fon", "freetype"); // Windows bitmap fonts 321 addFileExtensionAlias("fnt", "freetype"); // Windows bitmap fonts 322 321 addFileExtensionAlias("fnt", "freetype"); // Windows bitmap fonts 322 addFileExtensionAlias("text3d", "freetype"); // use 3D Font instead of 2D Font 323 323 324 // wont't add type1 and type2 until resolve extension collision with Performer binary and ascii files. 324 325 // addFileExtensionAlias("pfb", "freetype"); // type1 binary -
OpenSceneGraph/trunk/src/osgPlugins/freetype/FreeTypeFont3D.cpp
r7696 r9881 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 21 21 22 22 #include <osg/Geometry> 23 #include <osg/Notify> 23 #include <osg/Notify> 24 24 #include <osgDB/WriteFile> 25 25 #include <osgUtil/SmoothingVisitor> … … 27 27 28 28 29 #include <ft2build.h> 29 #include <ft2build.h> 30 30 #include FT_FREETYPE_H 31 31 … … 174 174 { 175 175 Char3DInfo* char3d = (Char3DInfo*)user; 176 char3d->cubicTo( 176 char3d->cubicTo( 177 177 osg::Vec2(FT_NUM(control1->x),FT_NUM(control1->y)), 178 178 osg::Vec2(FT_NUM(control2->x),FT_NUM(control2->y)), … … 221 221 } 222 222 223 FT_Set_Char_Size( _face, 64*64, 64*64, 600, 600); 223 FT_Set_Char_Size( _face, 64*64, 64*64, 600, 600); 224 224 225 225 int glyphIndex = FT_Get_Char_Index( _face, 'M' ); … … 291 291 // not dangling pointers remain 292 292 freeTypeLibrary->removeFont3DImplmentation(this); 293 293 294 294 // free the freetype font face itself 295 295 FT_Done_Face(_face); … … 309 309 osgText::Font3D::Glyph3D * FreeTypeFont3D::getGlyph(unsigned int charcode) 310 310 { 311 312 311 312 313 313 // 314 // GT: fix for symbol fonts (i.e. the Webdings font) as the wrong character are being 315 // returned, for symbol fonts in windows (FT_ENCONDING_MS_SYMBOL in freetype) the correct 316 // values are from 0xF000 to 0xF0FF not from 0x000 to 0x00FF (0 to 255) as you would expect. 314 // GT: fix for symbol fonts (i.e. the Webdings font) as the wrong character are being 315 // returned, for symbol fonts in windows (FT_ENCONDING_MS_SYMBOL in freetype) the correct 316 // values are from 0xF000 to 0xF0FF not from 0x000 to 0x00FF (0 to 255) as you would expect. 317 317 // Microsoft uses a private field for its symbol fonts 318 318 // … … 337 337 return 0; 338 338 } 339 339 340 340 // ** init FreeType to describe the glyph 341 341 Char3DInfo char3d; … … 349 349 funcs.shift = 0; 350 350 funcs.delta = 0; 351 351 352 352 // ** record description 353 353 FT_Error _error = FT_Outline_Decompose(&outline, &funcs, &char3d); … … 357 357 return 0; 358 358 } 359 359 360 360 // ** create geometry for each part of the glyph 361 361 osg::ref_ptr<osg::Geometry> frontGeo(new osg::Geometry); 362 362 frontGeo->setVertexArray(char3d.get()->getVertexArray()); 363 363 frontGeo->setPrimitiveSetList(char3d.get()->getPrimitiveSetList()); 364 364 365 365 osg::ref_ptr<osg::Geometry> wallGeo(new osg::Geometry); 366 366 wallGeo->setVertexArray(frontGeo->getVertexArray()); 367 367 368 368 osg::ref_ptr<osg::Geometry> backGeo(new osg::Geometry); 369 369 backGeo->setVertexArray(frontGeo->getVertexArray()); 370 371 372 373 // ** for conveni ance.370 371 372 373 // ** for convenience. 374 374 osg::Vec3Array * vertices = char3d._verts.get(); 375 376 377 378 // ** duplicate the vertex for the back face 375 376 377 378 // ** duplicate the vertex for the back face 379 379 // ** with a depth equal to the font depth 380 380 std::size_t len = vertices->size(); 381 381 std::size_t dlen = len * 2; 382 382 383 383 vertices->reserve(dlen); 384 384 385 385 osg::Vec3Array::iterator begin = vertices->begin(); 386 386 osg::Vec3Array::iterator it = vertices->begin(); 387 387 388 388 for (std::size_t i = 0; i != len; ++i, ++it) 389 389 vertices->push_back(*it); 390 390 // std::copy(begin, begin + len, begin + len + 1); TOCHECK 391 392 391 392 393 393 // ** and decal new vertices 394 394 unsigned int depth = _facade->getFontDepth(); … … 397 397 (*vertices)[i].z() -= depth; 398 398 } 399 399 400 400 osg::Vec3Array::iterator end; 401 401 402 402 // ** create wall and back face from the front polygon 403 // ** then accumulate them in the ap ropriate geometry wallGeo and backGeo403 // ** then accumulate them in the appropriate geometry wallGeo and backGeo 404 404 for (std::size_t i=0; i < frontGeo->getNumPrimitiveSets(); ++i) 405 405 { … … 408 408 unsigned int idx = daFront->getFirst(); 409 409 unsigned int cnt = daFront->getCount(); 410 410 411 411 // ** reverse vertices to draw the front face in the CCW 412 412 std::reverse(begin + idx, begin + idx + cnt); 413 413 414 414 // ** create the back polygon 415 415 osg::ref_ptr<osg::DrawArrays> daBack(new osg::DrawArrays(osg::PrimitiveSet::POLYGON, idx + len, cnt)); 416 416 backGeo->addPrimitiveSet(daBack.get()); 417 418 417 418 419 419 // ** create the wall triangle strip 420 osg::ref_ptr<osg::DrawElementsUInt> deWall(new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLE_STRIP)); 420 osg::ref_ptr<osg::DrawElementsUInt> deWall(new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLE_STRIP)); 421 421 wallGeo->addPrimitiveSet(deWall.get()); 422 422 423 423 // ** link triangle strip 424 424 deWall->push_back(idx + len); 425 425 for (unsigned int j = 1; j < cnt; ++j) 426 { 426 { 427 427 deWall->push_back(idx + cnt - j); 428 428 deWall->push_back(idx + len + j); … … 440 440 ts.retessellatePolygons(*frontGeo); 441 441 } 442 442 443 443 { 444 444 osgUtil::Tessellator ts; … … 455 455 geode->accept(sm); 456 456 } 457 458 // ** save vertices and PrimitiveSetList of each face in the Glyph3D PrimitiveSet face list 457 458 // ** save vertices and PrimitiveSetList of each face in the Glyph3D PrimitiveSet face list 459 459 osgText::Font3D::Glyph3D * glyph3D = new osgText::Font3D::Glyph3D(charcode); 460 460 461 461 glyph3D->setVertexArray(dynamic_cast<osg::Vec3Array*>(frontGeo->getVertexArray())); 462 462 glyph3D->setNormalArray(dynamic_cast<osg::Vec3Array*>(wallGeo->getNormalArray())); 463 463 464 glyph3D->getFrontPrimitiveSetList() = frontGeo->getPrimitiveSetList(); 464 465 glyph3D->getWallPrimitiveSetList() = wallGeo->getPrimitiveSetList(); 465 466 glyph3D->getBackPrimitiveSetList() = backGeo->getPrimitiveSetList(); 466 467 467 468 468 469 FT_Glyph_Metrics* metrics = &(_face->glyph->metrics); 469 470 … … 476 477 glyph3D->setHeight((float)metrics->height / 64.0f); 477 478 478 479 479 480 FT_BBox ftbb; 480 481 FT_Outline_Get_BBox(&outline, &ftbb); … … 484 485 long ymin = ft_floor( ftbb.yMin ); 485 486 long ymax = ft_ceiling( ftbb.yMax ); 486 487 487 488 osg::BoundingBox bb(xmin / 64.0f, ymin / 64.0f, 0.0f, xmax / 64.0f, ymax / 64.0f, 0.0f); 488 489 489 490 glyph3D->setBoundingBox(bb); 490 491 491 492 return glyph3D; 492 493 } … … 501 502 FT_UInt left = FT_Get_Char_Index( _face, leftcharcode ); 502 503 FT_UInt right = FT_Get_Char_Index( _face, rightcharcode ); 503 504 // get the kerning distances. 504 505 // get the kerning distances. 505 506 FT_Vector kerning; 506 507 … … 525 526 } 526 527 527 float FreeTypeFont3D::getScale() const 528 { 529 return _scale; 530 } 528 float FreeTypeFont3D::getScale() const 529 { 530 return _scale; 531 } -
OpenSceneGraph/trunk/src/osgPlugins/freetype/ReaderWriterFreeType.cpp
r8680 r9881 18 18 supportsExtension("cff","OpenType format"); 19 19 supportsExtension("cef","OpenType format"); 20 supportsExtension("fon","Windows bitmap fonts format");20 supportsExtension("fon","Windows bitmap fonts format"); 21 21 supportsExtension("fnt","Windows bitmap fonts format"); 22 supportsExtension("text3d","use 3D Font instead of 2D Font"); 22 23 23 24 supportsOption("monochrome","Select monochrome font."); 24 25 } 25 26 26 27 virtual const char* className() const { return "FreeType Font Reader/Writer"; } 27 28 28 29 static unsigned int getFlags(const osgDB::ReaderWriter::Options* options) 29 30 { … … 33 34 flags |= FT_LOAD_MONOCHROME; 34 35 } 35 36 36 37 return flags; 37 38 } … … 39 40 virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const 40 41 { 41 std::string ext = osgDB::getLowerCaseFileExtension(file); 42 std::string tmpFile = file; 43 bool needFont3D = false; 44 45 std::string ext = osgDB::getLowerCaseFileExtension(tmpFile); 46 if (ext == "text3d") 47 { 48 needFont3D = true; 49 tmpFile.erase(tmpFile.size()-7, 7); 50 ext = osgDB::getLowerCaseFileExtension(tmpFile); 51 } 52 else if ((options != NULL) && (options->getPluginData("3D"))) 53 { 54 needFont3D = true; 55 } 56 42 57 if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; 43 58 44 std::string fileName = osgDB::findDataFile( file, options );59 std::string fileName = osgDB::findDataFile( tmpFile, options ); 45 60 if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; 46 61 47 62 FreeTypeLibrary* freeTypeLibrary = FreeTypeLibrary::instance(); 48 if (!freeTypeLibrary) 63 if (!freeTypeLibrary) 49 64 { 50 65 osg::notify(osg::WARN)<<"Warning:: cannot create freetype font after freetype library has been deleted."<<std::endl; … … 52 67 } 53 68 54 if ( (options != NULL) && (options->getPluginData("3D")))69 if (needFont3D) 55 70 return freeTypeLibrary->getFont3D(fileName,0,getFlags(options)); 56 71 else … … 61 76 { 62 77 FreeTypeLibrary* freeTypeLibrary = FreeTypeLibrary::instance(); 63 if (!freeTypeLibrary) 78 if (!freeTypeLibrary) 64 79 { 65 80 osg::notify(osg::WARN)<<"Warning:: cannot create freetype font after freetype library has been deleted."<<std::endl; -
OpenSceneGraph/trunk/src/osgText/Font3D.cpp
r7874 r9881 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 87 87 88 88 // Not found, return empty string 89 osg::notify(osg::WARN)<<"Warning: font file \""<<str<<"\" not found."<<std::endl; 89 osg::notify(osg::WARN)<<"Warning: font file \""<<str<<"\" not found."<<std::endl; 90 90 return std::string(); 91 91 } … … 95 95 if (filename=="") return 0; 96 96 97 std::string foundFile = findFont3DFile(filename); 97 // unsure filename have not .text3d at the end 98 std::string tmpFilename; 99 std::string text3dExt = ".text3d"; 100 std::string ext = osgDB::getFileExtensionIncludingDot(filename); 101 if (ext == text3dExt) 102 tmpFilename = filename.substr(filename.size() - ext.size(), ext.size()); 103 else 104 tmpFilename = filename; 105 106 //search font file 107 std::string foundFile = findFont3DFile(tmpFilename); 98 108 if (foundFile.empty()) return 0; 99 109 110 //unsure filename have .text3d at the end 111 foundFile += text3dExt; 112 100 113 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_Font3DFileMutex); 101 114 … … 105 118 localOptions = new osgDB::ReaderWriter::Options; 106 119 localOptions->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS); 107 // ** HACK to load Font3D instead of Font108 localOptions->setPluginData("3D", (void*) 1);109 }110 else111 {112 userOptions->setPluginData("3D", (void*) 1);113 120 } 114 121 115 122 osg::Object* object = osgDB::readObjectFile(foundFile, userOptions ? userOptions : localOptions.get()); 116 123 117 124 // if the object is a font then return it. 118 125 osgText::Font3D* font3D = dynamic_cast<osgText::Font3D*>(object); … … 143 150 osgDB::ReaderWriter *reader = osgDB::Registry::instance()->getReaderWriterForExtension("ttf"); 144 151 if (reader == 0) return 0; 145 152 146 153 osgDB::ReaderWriter::ReadResult rr = reader->readObject(stream, userOptions ? userOptions : localOptions.get()); 147 154 if (rr.error()) … … 151 158 } 152 159 if (!rr.validObject()) return 0; 153 160 154 161 osg::Object *object = rr.takeObject(); 155 162 … … 167 174 if (filename=="") return 0; 168 175 169 std::string foundFile = findFont3DFile(filename); 176 std::string tmpFilename; 177 std::string text3dExt = ".text3d"; 178 std::string ext = osgDB::getFileExtensionIncludingDot(filename); 179 if (ext == text3dExt) 180 tmpFilename = filename.substr(0, filename.size() - ext.size()); 181 else 182 tmpFilename = filename; 183 184 std::string foundFile = findFont3DFile(tmpFilename); 170 185 if (foundFile.empty()) return 0; 171 186 187 foundFile += text3dExt; 188 172 189 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_Font3DFileMutex); 173 190 … … 177 194 localOptions = new osgDB::ReaderWriter::Options; 178 195 localOptions->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS); 179 // ** HACK to load Font3D instead of Font180 localOptions->setPluginData("3D", (void*) 1);181 }182 else183 {184 userOptions->setPluginData("3D", (void*) 1);185 196 } 186 197 187 198 osg::ref_ptr<osg::Object> object = osgDB::readRefObjectFile(foundFile, userOptions ? userOptions : localOptions.get()); 188 199 189 200 // if the object is a font then return it. 190 201 osgText::Font3D* font3D = dynamic_cast<osgText::Font3D*>(object.get()); … … 213 224 osgDB::ReaderWriter *reader = osgDB::Registry::instance()->getReaderWriterForExtension("ttf"); 214 225 if (reader == 0) return 0; 215 226 216 227 osgDB::ReaderWriter::ReadResult rr = reader->readObject(stream, userOptions ? userOptions : localOptions.get()); 217 228 if (rr.error()) … … 268 279 Font3D::Glyph3D* Font3D::getGlyph(unsigned int charcode) 269 280 { 270 Glyph3D * glyph3D = NULL; 271 281 Glyph3D * glyph3D = NULL; 282 272 283 Glyph3DMap::iterator itr = _glyph3DMap.find(charcode); 273 284 if (itr!=_glyph3DMap.end()) glyph3D = itr->second.get(); 274 285 275 286 else if (_implementation.valid()) 276 287 { … … 278 289 if (glyph3D) _glyph3DMap[charcode] = glyph3D; 279 290 } 280 291 281 292 return glyph3D; 282 293 } … … 285 296 { 286 297 Glyph3DMap::iterator it,end = _glyph3DMap.end(); 287 298 288 299 for (it=_glyph3DMap.begin(); it!=end; ++it) 289 300 it->second->setThreadSafeRefUnref(threadSafe); -
OpenSceneGraph/trunk/src/osgText/Text3D.cpp
r8868 r9881 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 14 14 #include <osgText/Text3D> 15 15 #include <osg/io_utils> 16 namespace osgText 16 namespace osgText 17 17 { 18 18 … … 33 33 } 34 34 35 //void Text3D::accept(osg::Drawable::ConstAttributeFunctor& af) const 36 //{ 37 // TODO 38 //} 39 40 //void Text3D::accept(osg::PrimitiveFunctor& /*pf*/) const 41 //{ 42 // TODO 43 //} 35 void Text3D::accept(osg::Drawable::ConstAttributeFunctor& af) const 36 { 37 // ** for each line, do ... 38 TextRenderInfo::const_iterator itLine, endLine = _textRenderInfo.end(); 39 for (itLine = _textRenderInfo.begin(); itLine!=endLine; ++itLine) 40 { 41 // ** for each glyph in the line, do ... 42 LineRenderInfo::const_iterator it, end = itLine->end(); 43 for (it = itLine->begin(); it!=end; ++it) 44 { 45 // ** apply the vertex array 46 af.apply(osg::Drawable::VERTICES, it->_glyph->getVertexArray()->size(), &(it->_glyph->getVertexArray()->front())); 47 } 48 } 49 } 50 void Text3D::accept(osg::PrimitiveFunctor& pf) const 51 { 52 // ** for each line, do ... 53 TextRenderInfo::const_iterator itLine, endLine = _textRenderInfo.end(); 54 for (itLine = _textRenderInfo.begin(); itLine!=endLine; ++itLine) 55 { 56 // ** for each glyph in the line, do ... 57 LineRenderInfo::const_iterator it, end = itLine->end(); 58 for (it = itLine->begin(); it!=end; ++it) 59 { 60 pf.setVertexArray(it->_glyph->getVertexArray()->size(),&(it->_glyph->getVertexArray()->front())); 61 62 // ** render the front face of the glyph 63 osg::Geometry::PrimitiveSetList & pslFront = it->_glyph->getFrontPrimitiveSetList(); 64 for(osg::Geometry::PrimitiveSetList::const_iterator itr=pslFront.begin(), end = pslFront.end(); itr!=end; ++itr) 65 { 66 (*itr)->accept(pf); 67 } 68 69 // ** render the wall face of the glyph 70 osg::Geometry::PrimitiveSetList & pslWall = it->_glyph->getWallPrimitiveSetList(); 71 for(osg::Geometry::PrimitiveSetList::const_iterator itr=pslWall.begin(), end=pslWall.end(); itr!=end; ++itr) 72 { 73 (*itr)->accept(pf); 74 } 75 76 // ** render the back face of the glyph 77 osg::Geometry::PrimitiveSetList & pslBack = it->_glyph->getBackPrimitiveSetList(); 78 for(osg::Geometry::PrimitiveSetList::const_iterator itr=pslBack.begin(), end=pslBack.end(); itr!=end; ++itr) 79 { 80 (*itr)->accept(pf); 81 } 82 } 83 } 84 } 44 85 45 86 void Text3D::setFont(osg::ref_ptr<Font3D> font) 46 { 87 { 47 88 _font = font; 48 89 49 90 computeGlyphRepresentation(); 50 91 } 51 92 52 93 void Text3D::setFont(const std::string & fontfile) 53 { 94 { 54 95 setFont(readRefFont3DFile(fontfile)); 55 96 } … … 76 117 float maximumHeight = _maximumHeight / _font->getScale(); 77 118 float maximumWidth = _maximumWidth / _font->getScale(); 78 119 79 120 for(bool outOfSpace=false;lastChar!=last;++lastChar) 80 121 { 81 122 unsigned int charcode = *lastChar; 82 123 83 124 if (charcode=='\n') 84 125 { … … 90 131 { 91 132 const osg::BoundingBox & bb = glyph->getBoundingBox(); 92 133 93 134 // adjust cursor position w.r.t any kerning. 94 135 if (previous_charcode) 95 136 { 96 137 97 138 if (_layout == RIGHT_TO_LEFT) 98 139 { 99 140 cursor.x() -= glyph->getHorizontalAdvance(); 100 141 } 101 142 102 143 if (kerning) 103 144 { … … 120 161 } 121 162 else 122 { 163 { 123 164 switch (_layout) 124 165 { … … 136 177 break; 137 178 } 138 139 } 140 141 179 180 } 181 182 142 183 143 184 switch(_layout) … … 159 200 break; 160 201 } 161 202 162 203 // => word boundary detection & wrapping 163 204 if (outOfSpace) break; … … 176 217 177 218 } 178 219 179 220 // word boundary detection & wrapping 180 221 if (lastChar!=last) 181 222 { 182 if (deliminatorSet.count(*lastChar)==0) 223 if (deliminatorSet.count(*lastChar)==0) 183 224 { 184 225 String::iterator lastValidChar = lastChar; … … 186 227 { 187 228 --lastValidChar; 188 229 189 230 //Substract off glyphs from the cursor position (to correctly center text) 190 231 Font3D::Glyph3D* glyph = _font->getGlyph(*lastValidChar); … … 199 240 } 200 241 } 201 242 202 243 if (first!=lastValidChar) 203 244 { … … 214 255 { 215 256 if (_font.valid() == false) return; 216 257 217 258 _textRenderInfo.clear(); 218 259 _lineCount = 0; 219 220 if (_text.empty()) 260 261 if (_text.empty()) 221 262 { 222 263 _textBB.set(0,0,0, 0,0,0);//no size text … … 224 265 return; 225 266 } 226 267 227 268 // initialize bounding box, it will be expanded during glyph position calculation 228 269 _textBB.init(); … … 232 273 osg::Vec2 local(0.0f,0.0f); 233 274 osg::Vec2 startOffset(0.0f,0.0f); 234 275 235 276 unsigned int previous_charcode = 0; 236 277 unsigned int linelength = 0; 237 278 bool kerning = true; 238 279 239 280 unsigned int lineNumber = 0; 240 281 241 282 242 283 243 284 for(String::iterator itr=_text.begin(); itr!=_text.end(); ) … … 245 286 _textRenderInfo.resize(lineNumber + 1); 246 287 LineRenderInfo & currentLineRenderInfo = _textRenderInfo.back(); 247 288 248 289 // record the start of the current line 249 290 String::iterator startOfLine_itr = itr; … … 252 293 osg::Vec2 endOfLine_coords(cursor); 253 294 String::iterator endOfLine_itr = computeLastCharacterOnLine(endOfLine_coords, itr,_text.end()); 254 255 // ** position the cursor function to the Layout and the alignement 295 296 // ** position the cursor function to the Layout and the alignement 256 297 TextBase::positionCursor(endOfLine_coords, cursor, (unsigned int) (endOfLine_itr - startOfLine_itr)); 257 298 258 299 259 300 if (itr!=endOfLine_itr) 260 301 { … … 267 308 { 268 309 const osg::BoundingBox & bb = glyph->getBoundingBox(); 269 310 270 311 // adjust cursor position w.r.t any kerning. 271 312 if (previous_charcode) … … 275 316 cursor.x() -= glyph->getHorizontalAdvance(); 276 317 } 277 318 278 319 if (kerning) 279 320 { … … 296 337 } 297 338 else 298 { 339 { 299 340 switch (_layout) 300 341 { … … 315 356 } 316 357 } 317 358 318 359 } 319 360 320 361 local = cursor; 321 362 322 363 if (_layout==VERTICAL) 323 364 { … … 325 366 local.y() += -glyph->getVerticalBearing().y(); 326 367 } 327 328 329 368 369 370 330 371 // move the cursor onto the next character. 331 372 // also expand bounding box … … 345 386 _textBB.expandBy(osg::Vec3(cursor.x()+bb.xMax(), cursor.y() + bb.yMax(), 0.0f)); //upper right corner 346 387 _textBB.expandBy(osg::Vec3(cursor.x()+bb.xMin(), cursor.y()+bb.yMin(), 0.0f)); //lower left corner 347 388 348 389 break; 349 390 } 350 391 351 392 osg::Vec3 pos = osg::Vec3(local.x(), local.y(), 0.0f); 352 393 currentLineRenderInfo.push_back(Text3D::GlyphRenderInfo(glyph, pos)); 353 394 354 395 355 396 previous_charcode = charcode; 356 397 } … … 361 402 ++itr; 362 403 } 363 404 364 405 if (itr!=_text.end()) 365 406 { … … 367 408 if (*itr=='\n') ++itr; 368 409 } 369 410 370 411 // move to new line. 371 412 switch(_layout) … … 395 436 } 396 437 _textBB.expandBy(0.0f,0.0f,-1); 397 438 398 439 TextBase::computePositions(); 399 440 } 400 401 402 441 403 442 osg::BoundingBox Text3D::computeBound() const … … 411 450 osg::Matrix& matrix = _autoTransformCache[i]._matrix; 412 451 bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMin(),_textBB.zMin())*matrix); 413 // bbox.expandBy(osg::Vec3(_textBB.xMax(),_textBB.yMin(),_textBB.zMin())*matrix);414 452 bbox.expandBy(osg::Vec3(_textBB.xMax(),_textBB.yMax(),_textBB.zMax())*matrix); 415 // bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMax(),_textBB.zMin())*matrix); 416 } 417 } 418 453 } 454 } 455 419 456 return bbox; 420 457 } 421 458 422 423 424 425 426 427 428 459 void Text3D::computePositions(unsigned int contextID) const 429 460 { 430 461 if (_font.valid() == false) return; 431 462 432 463 switch(_alignment) 433 464 { … … 447 478 case CENTER_BASE_LINE: _offset.set((_textBB.xMax()+_textBB.xMin())*0.5f,0.0f,0.0f); break; 448 479 case RIGHT_BASE_LINE: _offset.set(_textBB.xMax(),0.0f,0.0f); break; 449 480 450 481 case LEFT_BOTTOM_BASE_LINE: _offset.set(0.0f,-_characterHeight*(_lineCount-1),0.0f); break; 451 482 case CENTER_BOTTOM_BASE_LINE: _offset.set((_textBB.xMax()+_textBB.xMin())*0.5f,-_characterHeight*(_lineCount-1),0.0f); break; 452 483 case RIGHT_BOTTOM_BASE_LINE: _offset.set(_textBB.xMax(),-_characterHeight*(_lineCount-1),0.0f); break; 453 484 } 454 485 455 486 AutoTransformCache& atc = _autoTransformCache[contextID]; 456 487 osg::Matrix& matrix = atc._matrix; 457 488 458 489 459 490 float scale = _font->getScale(); 460 491 osg::Vec3 scaleVec(scale * _characterHeight, scale * _characterHeight / _characterAspectRatio, _characterDepth); … … 464 495 matrix.postMultTranslate(_position); 465 496 466 497 467 498 _normal = osg::Matrix::transform3x3(osg::Vec3(0.0f,0.0f,1.0f),matrix); 468 499 _normal.normalize(); 469 500 470 const_cast<Text3D*>(this)->dirtyBound(); 501 const_cast<Text3D*>(this)->dirtyBound(); 471 502 } 472 503 … … 475 506 osg::State & state = *renderInfo.getState(); 476 507 unsigned int contextID = state.getContextID(); 477 478 508 509 479 510 // ** save the previous modelview matrix 480 511 osg::ref_ptr<osg::RefMatrix> previous(new osg::RefMatrix(state.getModelViewMatrix())); … … 485 516 // ** mult previous by the modelview for this context 486 517 modelview->postMult(*previous.get()); 487 518 488 519 // ** apply this new modelview matrix 489 520 state.applyModelViewMatrix(modelview.get()); 490 491 521 522 492 523 if (_drawMode & TEXT) 493 524 { 494 525 renderInfo.getState()->disableAllVertexArrays(); 495 526 496 527 glPushAttrib(GL_TRANSFORM_BIT); 497 528 glEnable(GL_RESCALE_NORMAL); 498 529 499 530 switch(_renderMode) 500 531 { … … 503 534 default: renderPerGlyph(*renderInfo.getState()); break; 504 535 } 505 536 506 537 glPopAttrib(); 507 538 } … … 515 546 osg::Vec3 c110(osg::Vec3(_textBB.xMax(),_textBB.yMax(),_textBB.zMax())); 516 547 osg::Vec3 c010(osg::Vec3(_textBB.xMin(),_textBB.yMax(),_textBB.zMax())); 517 548 518 549 osg::Vec3 c001(osg::Vec3(_textBB.xMin(),_textBB.yMin(),_textBB.zMin())); 519 550 osg::Vec3 c101(osg::Vec3(_textBB.xMax(),_textBB.yMin(),_textBB.zMin())); 520 551 osg::Vec3 c111(osg::Vec3(_textBB.xMax(),_textBB.yMax(),_textBB.zMin())); 521 552 osg::Vec3 c011(osg::Vec3(_textBB.xMin(),_textBB.yMax(),_textBB.zMin())); 522 553 523 554 glBegin(GL_LINE_LOOP); 524 555 glVertex3fv(c000.ptr()); … … 527 558 glVertex3fv(c010.ptr()); 528 559 glEnd(); 529 560 530 561 glBegin(GL_LINE_LOOP); 531 562 glVertex3fv(c001.ptr()); … … 534 565 glVertex3fv(c101.ptr()); 535 566 glEnd(); 536 567 537 568 glBegin(GL_LINES); 538 569 glVertex3fv(c000.ptr()); 539 570 glVertex3fv(c001.ptr()); 540 571 541 572 glVertex3fv(c100.ptr()); 542 573 glVertex3fv(c101.ptr()); 543 574 544 575 glVertex3fv(c110.ptr()); 545 576 glVertex3fv(c111.ptr()); 546 577 547 578 glVertex3fv(c010.ptr()); 548 579 glVertex3fv(c011.ptr()); 549 580 glEnd(); 550 581 } 551 } 582 } 552 583 553 584 if (_drawMode & ALIGNMENT) … … 566 597 glVertex3fv(vb.ptr()); 567 598 glEnd(); 568 599 569 600 } 570 601 … … 573 604 } 574 605 575 576 577 606 void Text3D::renderPerGlyph(osg::State & state) const 578 { 607 { 579 608 // ** for each line, do ... 580 609 TextRenderInfo::const_iterator itLine, endLine = _textRenderInfo.end(); … … 585 614 for (it = itLine->begin(); it!=end; ++it) 586 615 { 587 616 588 617 glPushMatrix(); 589 618 590 619 glTranslatef(it->_position.x(), it->_position.y(), it->_position.z()); 591 620 592 621 // ** apply the vertex array 593 622 state.setVertexPointer(it->_glyph->getVertexArray()); 594 623 595 624 // ** render the front face of the glyph 596 625 glNormal3f(0.0f,0.0f,1.0f); 597 626 598 627 osg::Geometry::PrimitiveSetList & pslFront = it->_glyph->getFrontPrimitiveSetList(); 599 628 for(osg::Geometry::PrimitiveSetList::const_iterator itr=pslFront.begin(), end = pslFront.end(); itr!=end; ++itr) 600 629 { 601 602 630 (*itr)->draw(state, false); 603 631 } 604 632 605 633 // ** render the wall face of the glyph 606 634 state.setNormalPointer(it->_glyph->getNormalArray()); … … 610 638 (*itr)->draw(state, false); 611 639 } 612 640 state.disableNormalPointer(); 641 613 642 // ** render the back face of the glyph 614 643 glNormal3f(0.0f,0.0f,-1.0f); 615 644 616 645 osg::Geometry::PrimitiveSetList & pslBack = it->_glyph->getBackPrimitiveSetList(); 617 646 for(osg::Geometry::PrimitiveSetList::const_iterator itr=pslBack.begin(), end=pslBack.end(); itr!=end; ++itr) … … 619 648 (*itr)->draw(state, false); 620 649 } 621 650 622 651 glPopMatrix(); 623 652 } … … 629 658 // ** render all front faces 630 659 glNormal3f(0.0f,0.0f,1.0f); 631 660 632 661 TextRenderInfo::const_iterator itLine, endLine = _textRenderInfo.end(); 633 662 for (itLine = _textRenderInfo.begin(); itLine!=endLine; ++itLine) … … 635 664 // ** for each glyph in the line, do ... 636 665 LineRenderInfo::const_iterator it, end = itLine->end(); 637 for (it = itLine->begin(); it!=end; ++it) 666 for (it = itLine->begin(); it!=end; ++it) 638 667 { 639 668 glPushMatrix(); 640 669 glTranslatef(it->_position.x(), it->_position.y(), it->_position.z()); 641 670 state.setVertexPointer(it->_glyph->getVertexArray()); 642 671 643 672 // ** render the front face of the glyph 644 673 osg::Geometry::PrimitiveSetList & psl = it->_glyph->getFrontPrimitiveSetList(); … … 650 679 } 651 680 } 652 681 653 682 654 683 // ** render all wall face of the text … … 663 692 state.setVertexPointer(it->_glyph->getVertexArray()); 664 693 state.setNormalPointer(it->_glyph->getNormalArray()); 665 694 666 695 osg::Geometry::PrimitiveSetList & psl = it->_glyph->getWallPrimitiveSetList(); 667 696 for(osg::Geometry::PrimitiveSetList::const_iterator itr=psl.begin(), end=psl.end(); itr!=end; ++itr) … … 673 702 } 674 703 675 704 676 705 // ** render all back face of the text 677 706 glNormal3f(0.0f,0.0f,-1.0f); 678 707 679 708 for (itLine = _textRenderInfo.begin(); itLine!=endLine; ++itLine) 680 709 { … … 686 715 glTranslatef(it->_position.x(), it->_position.y(), it->_position.z()); 687 716 state.setVertexPointer(it->_glyph->getVertexArray()); 688 717 689 718 // ** render the back face of the glyph 690 719 osg::Geometry::PrimitiveSetList & psl = it->_glyph->getBackPrimitiveSetList(); … … 710 739 { 711 740 TextBase::resizeGLObjectBuffers(maxSize); 712 741 713 742 if (_font.valid()) _font->resizeGLObjectBuffers(maxSize); 714 743 } … … 717 746 { 718 747 TextBase::releaseGLObjects(state); 719 748 720 749 if (_font.valid()) _font->releaseGLObjects(state); 721 750 }
