openscenegraph
Text3D
Go to the documentation of this file.
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/Style>
20
21namespace osgText {
22
23
24class OSGTEXT_EXPORT Text3D : public osgText::TextBase
25{
26 public:
27
28 /** Deprecated.*/
29 enum RenderMode
30 {
31 PER_FACE,
32 PER_GLYPH
33 };
34
35 Text3D();
36 Text3D(const Text3D& text,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
37
38 META_Object(osgText,Text3D)
39
40 /** Get the Charactere Depth of text. */
41 float getCharacterDepth() const;
42
43 /** Set the Charactere Depth of text. */
44 void setCharacterDepth(float characterDepth);
45
46 /** Deprecated, value is now ignored. */
47 RenderMode getRenderMode() const { return _renderMode; }
48 /** Deprecated, value is now ignored. */
49 void setRenderMode(RenderMode renderMode) { _renderMode = renderMode; }
50
51
52 /** Get the wall StateSet */
53 osg::StateSet* getWallStateSet() { return _wallStateSet.get(); }
54 /** Get the wall StateSet */
55 const osg::StateSet* getWallStateSet() const { return _wallStateSet.get(); }
56 /** Get or create the wall StateSet */
57 osg::StateSet* getOrCreateWallStateSet()
58 {
59 if (_wallStateSet.valid() == false) _wallStateSet = new osg::StateSet;
60 return _wallStateSet.get();
61 }
62 /** Set the wall StateSet */
63 void setWallStateSet(osg::StateSet* wallStateSet) { _wallStateSet = wallStateSet; }
64
65 /** Get the back StateSet */
66 osg::StateSet* getBackStateSet() { return _backStateSet.get(); }
67 /** Get the back StateSet */
68 osg::StateSet* getBackStateSet() const { return _backStateSet.get(); }
69 /** Get or create the back StateSet */
70 osg::StateSet* getOrCreateBackStateSet() { if (_backStateSet.valid() == false) _backStateSet = new osg::StateSet; return _backStateSet.get(); }
71 /** Set the back StateSet */
72 void setBackStateSet(osg::StateSet* backStateSet) { _backStateSet = backStateSet; }
73
74
75
76 /** Draw the text.*/
77 virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
78
79 /** return false, osgText::Text does not support accept(AttributeFunctor&).*/
80 virtual bool supports(const osg::Drawable::AttributeFunctor&) const { return false; }
81
82 /** return true, osgText::Text does support accept(ConstAttributeFunctor&).*/
83 virtual bool supports(const osg::Drawable::ConstAttributeFunctor&) const { return false; }
84
85 /** accept an ConstAttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has.*/
86 virtual void accept(osg::Drawable::ConstAttributeFunctor& af) const;
87
88 /** return true, osgText::Text does support accept(PrimitiveFunctor&) .*/
89 virtual bool supports(const osg::PrimitiveFunctor&) const { return false; }
90
91 /** accept a PrimtiveFunctor and call its methods to tell it about the internal primtives that this Drawable has.*/
92 virtual void accept(osg::PrimitiveFunctor& pf) const;
93
94 /** Resize any per context GLObject buffers to specified size. */
95 virtual void resizeGLObjectBuffers(unsigned int maxSize);
96
97 /** If State is non-zero, this function releases OpenGL objects for
98 * the specified graphics context. Otherwise, releases OpenGL objexts
99 * for all graphics contexts. */
100 virtual void releaseGLObjects(osg::State* state=0) const;
101
102 // make Font a friend to allow it set the _font to 0 if the font is
103 // forcefully unloaded.
104 friend class Font;
105
106 virtual osg::BoundingBox computeBoundingBox() const;
107
108
109 protected:
110
111 virtual ~Text3D() {}
112
113 String::iterator computeLastCharacterOnLine(osg::Vec2& cursor, String::iterator first,String::iterator last);
114
115 void computeGlyphRepresentation();
116
117 void copyAndOffsetPrimitiveSets(osg::Geometry::PrimitiveSetList& dest_PrimitiveSetList, osg::Geometry::PrimitiveSetList& src_PrimitiveSetList, unsigned int offset);
118
119 osg::Geometry::PrimitiveSetList _frontPrimitiveSetList;
120 osg::Geometry::PrimitiveSetList _wallPrimitiveSetList;
121 osg::Geometry::PrimitiveSetList _backPrimitiveSetList;
122
123 // ** glyph and other information to render the glyph
124 struct GlyphRenderInfo
125 {
126 GlyphRenderInfo(GlyphGeometry* glyphGeometry, osg::Vec3 & pos):
127 _glyphGeometry(glyphGeometry),
128 _position(pos) {}
129
130 osg::ref_ptr<GlyphGeometry> _glyphGeometry;
131 osg::Vec3 _position;
132 };
133
134 typedef std::vector<GlyphRenderInfo> LineRenderInfo;
135 typedef std::vector<LineRenderInfo> TextRenderInfo;
136
137 TextRenderInfo _textRenderInfo;
138
139 // deprecated value no longer used.
140 RenderMode _renderMode;
141
142 osg::ref_ptr<osg::StateSet> _wallStateSet;
143 osg::ref_ptr<osg::StateSet> _backStateSet;
144};
145
146}
147
148
149#endif