Show
Ignore:
Timestamp:
03/10/09 11:56:00 (5 years ago)
Author:
robert
Message:

From David Callu, "Problem:

osgText::Text and osgText::Text3D use the same font file.
The first really load the file and obtain an osgText::Font object,
the second use the cache created during the first load of the
font file, and so obtain an osgText::Font object instead of
osgText::Font3D object. To obtain an osgText::Font3D object,
osgText::Text3D call osgDB::readObjectFile(...) with an option
to specify the plugin we want an osgText::Font3D instead of
osgText::Font.

Generalised Problem:

In osgDB::Registry, loaded file cache is referenced by the name
of this file, so if I load a file with some options, and the cache
already contain object for this filename, I obtain an object
potentially not loaded with my options.

Behaviours:

Cache management is delegate to osgDB::Registry, but cache
coherence (load a file with option then reuse it, deactivate the
cache when load a specific file or don't cached the loaded file)
is user's responsibility.

Text3D solution:

Postfix the font file name by .text3d or something similar and then have the freetype plugin return
osgText::Font3D when it detects this.
This operation is done by osgText::readFont3DFile() which unsure the filename have .text3d as extension.
This is totaly transparent for user, and backward compatible.

BTW, I fix the bug about the Normal of 3D text. Currently, the front and wall face have
the same normal (0,0,1) in the Text3D object coordinate. Now the wall face have its own
normal array computed by the plugin.

BTW 2, I implement
- void Text3D::accept(osg::Drawable::ConstAttributeFunctor?& af) const
- void Text3D::accept(osg::PrimitiveFunctor?& pf) const
so now statistics are well reported.
"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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 
    22 * 
    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 
    55 * (at your option) any later version.  The full license is in LICENSE file 
    66 * included with this distribution, and on the openscenegraph.org website. 
    7  *  
     7 * 
    88 * This library is distributed in the hope that it will be useful, 
    99 * 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 
    1111 * OpenSceneGraph Public License for more details. 
    1212*/ 
     
    3131     *                   all wall face with the wall StateSet 
    3232     *                   all back face with the back StateSet (back face of the character, no the OpenGL back face) 
    33      *  
     33     * 
    3434     * PER_GLYPH : render all Charactere with the default StateSet 
    3535     */ 
     
    3939        PER_GLYPH 
    4040    }; 
    41      
     41 
    4242    Text3D(); 
    4343    Text3D(const Text3D& text,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 
     
    4949    /** Set the Charactere Depth of text. */ 
    5050    void setCharacterDepth(float characterDepth) { _characterDepth = characterDepth; computeGlyphRepresentation(); } 
    51      
     51 
    5252    /** Get the render mode used to render the text. */ 
    5353    RenderMode getRenderMode() const { return _renderMode; } 
     
    5858//    osg::StateSet * getWallStateSet() { return _wallStateSet.get(); } 
    5959//    /** 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(); 
    6464//    } 
    6565//    /** Set the wall StateSet */ 
     
    7272//    /** Set the back StateSet */ 
    7373//    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. 
    7777      * setFont(0) sets the use of the default font.*/ 
    7878    inline void setFont(Font3D* font=0) { setFont(osg::ref_ptr<Font3D>(font)); }; 
     
    8787    void setFont(const std::string& fontfile); 
    8888 
    89     /** Get the font. Return 0 if default is being used.*/     
     89    /** Get the font. Return 0 if default is being used.*/ 
    9090    const Font3D* getFont() const { return _font.get(); } 
    9191 
    92      
    93      
    94      
     92 
     93 
     94 
    9595    /** Draw the text.*/ 
    9696    virtual void drawImplementation(osg::RenderInfo& renderInfo) const; 
     
    103103 
    104104    /** 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; 
    106106 
    107107    /** return true, osgText::Text does support accept(PrimitiveFunctor&) .*/ 
     
    109109 
    110110    /** 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; 
    112112 
    113113 
     
    123123    virtual void releaseGLObjects(osg::State* state=0) const; 
    124124 
    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 
    126126//    // forcefully unloaded. 
    127127    friend class Font3D; 
     
    132132protected: 
    133133 
    134     virtual ~Text3D() {}  
    135      
     134    virtual ~Text3D() {} 
     135 
    136136    void renderPerGlyph(osg::State & state) const; 
    137137    void renderPerFace(osg::State & state) const; 
     
    141141    void computeGlyphRepresentation(); 
    142142    void computePositions(unsigned int contextID) const; 
    143      
     143 
    144144    // ** glyph and other information to render the glyph 
    145145    struct GlyphRenderInfo 
     
    147147        GlyphRenderInfo(Font3D::Glyph3D * glyph, osg::Vec3 & pos) : 
    148148            _glyph(glyph), _position(pos) {} 
    149                      
     149 
    150150        osg::ref_ptr<Font3D::Glyph3D> _glyph; 
    151151        osg::Vec3 _position; 
    152152    }; 
    153      
     153 
    154154    typedef std::vector<GlyphRenderInfo> LineRenderInfo; 
    155     typedef std::vector<LineRenderInfo> TextRenderInfo;     
    156      
     155    typedef std::vector<LineRenderInfo> TextRenderInfo; 
     156 
    157157    TextRenderInfo _textRenderInfo; 
    158158 
     
    160160 
    161161    float _characterDepth; 
    162      
     162 
    163163    RenderMode _renderMode; 
    164      
     164 
    165165    osg::ref_ptr<osg::StateSet> _wallStateSet; 
    166166    osg::ref_ptr<osg::StateSet> _backStateSet;