root/OpenSceneGraph/trunk/include/osgText/Text3D @ 8441

Revision 8441, 6.2 kB (checked in by robert, 6 years ago)

From David Callu, "fixed bounding box bug"

Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGTEXT_TEXT3D
15#define OSGTEXT_TEXT3D 1
16
17
18#include <osgText/TextBase>
19#include <osgText/Font3D>
20
21
22namespace osgText {
23
24
25class OSGTEXT_EXPORT Text3D : public osgText::TextBase
26{
27public:
28
29    /** Reder mode used to render the Text.
30     * PER_FACE : render all front face with the default StateSet
31     *                   all wall face with the wall StateSet
32     *                   all back face with the back StateSet (back face of the character, no the OpenGL back face)
33     *
34     * PER_GLYPH : render all Charactere with the default StateSet
35     */
36    enum RenderMode
37    {
38        PER_FACE,
39        PER_GLYPH
40    };
41   
42    Text3D();
43    Text3D(const Text3D& text,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
44
45    META_Object(osgText,Text3D)
46
47    /** Get the Charactere Depth of text. */
48    float getCharacterDepth() const { return _characterDepth; }
49    /** Set the Charactere Depth of text. */
50    void setCharacterDepth(float characterDepth) { _characterDepth = characterDepth; computeGlyphRepresentation(); }
51   
52    /** Get the render mode used to render the text. */
53    RenderMode getRenderMode() const { return _renderMode; }
54    /** Set the render mode used to render the text. */
55    void setRenderMode(RenderMode renderMode) { _renderMode = renderMode; computeGlyphRepresentation(); }
56
57//    /** Get the wall StateSet */
58//    osg::StateSet * getWallStateSet() { return _wallStateSet.get(); }
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();
64//    }
65//    /** Set the wall StateSet */
66//    void setWallStateSet(osg::StateSet * wallStateSet)  { _wallStateSet = wallStateSet; }
67//
68//    /** Get the back StateSet */
69//    osg::StateSet * getBackStateSet() { return _backStateSet.get(); }
70//    /** Get or create the back StateSet */
71//    osg::StateSet * getOrCreateBackStateSet() { if (_backStateSet.valid() == false) _backStateSet = new osg::StateSet; return _backStateSet.get(); }
72//    /** Set the back StateSet */
73//    void setBackStateSet(osg::StateSet * backStateSet)  { _backStateSet = backStateSet; }
74//           
75   
76    /** Set the Font to use to render the text. 
77      * 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
83
84    /** Set the font, loaded from the specified front file, to use to render the text,
85      * setFont("") sets the use of the default font.
86      * See the osgText::readFontFile function for how the font file will be located. */
87    void setFont(const std::string& fontfile);
88
89    /** Get the font. Return 0 if default is being used.*/   
90    const Font3D* getFont() const { return _font.get(); }
91
92   
93   
94   
95    /** Draw the text.*/
96    virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
97
98    /** return false, osgText::Text does not support accept(AttributeFunctor&).*/
99    virtual bool supports(const osg::Drawable::AttributeFunctor&) const { return false; }
100
101    /** return true, osgText::Text does support accept(ConstAttributeFunctor&).*/
102    virtual bool supports(const osg::Drawable::ConstAttributeFunctor&) const { return false; }
103
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;
106
107    /** return true, osgText::Text does support accept(PrimitiveFunctor&) .*/
108    virtual bool supports(const osg::PrimitiveFunctor&) const { return false; }
109
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;
112
113
114    /** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
115    virtual void setThreadSafeRefUnref(bool threadSafe);
116
117    /** Resize any per context GLObject buffers to specified size. */
118    virtual void resizeGLObjectBuffers(unsigned int maxSize);
119
120    /** If State is non-zero, this function releases OpenGL objects for
121      * the specified graphics context. Otherwise, releases OpenGL objexts
122      * for all graphics contexts. */
123    virtual void releaseGLObjects(osg::State* state=0) const;
124
125//    // make Font a friend to allow it set the _font to 0 if the font is
126//    // forcefully unloaded.
127    friend class Font3D;
128
129    virtual osg::BoundingBox computeBound() const;
130
131
132protected:
133
134    virtual ~Text3D() {}
135   
136    void renderPerGlyph(osg::State & state) const;
137    void renderPerFace(osg::State & state) const;
138
139    String::iterator computeLastCharacterOnLine(osg::Vec2& cursor, String::iterator first,String::iterator last);
140
141    void computeGlyphRepresentation();
142    void computePositions(unsigned int contextID) const;
143   
144    // ** glyph and other information to render the glyph
145    struct GlyphRenderInfo
146    {
147        GlyphRenderInfo(Font3D::Glyph3D * glyph, osg::Vec3 & pos) :
148            _glyph(glyph), _position(pos) {}
149                   
150        osg::ref_ptr<Font3D::Glyph3D> _glyph;
151        osg::Vec3 _position;
152    };
153   
154    typedef std::vector<GlyphRenderInfo> LineRenderInfo;
155    typedef std::vector<LineRenderInfo> TextRenderInfo;   
156   
157    TextRenderInfo _textRenderInfo;
158
159    osg::ref_ptr<Font3D> _font;
160
161    float _characterDepth;
162   
163    RenderMode _renderMode;
164   
165    osg::ref_ptr<osg::StateSet> _wallStateSet;
166    osg::ref_ptr<osg::StateSet> _backStateSet;
167};
168
169}
170
171
172#endif
Note: See TracBrowser for help on using the browser.