OpenSceneGraph 3.6.5
TextBase
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_TEXTBASE
15#define OSGTEXT_TEXTBASE 1
16
17#include <osg/Drawable>
18
19#include <osgText/String>
20#include <osgText/KerningType>
21#include <osgText/Font>
22
23namespace osgText {
24
25#define NEW_APPROACH
26
28{
29public:
30
33
34 //virtual osg::Object* cloneType() const { return new Text(); }
35 //virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new Text(*this,copyop); }
36 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const TextBase*>(obj)!=NULL; }
37 virtual const char* className() const { return "TextBase"; }
38 virtual const char* libraryName() const { return "osgText"; }
39
40 void setColor(const osg::Vec4& color);
41 const osg::Vec4& getColor() const { return _color; }
42
45 virtual void setFont(Font* font=0) { setFont(osg::ref_ptr<Font>(font)); };
46
48 virtual void setFont(osg::ref_ptr<Font> font);
49
53 virtual void setFont(const std::string& fontfile);
54
56 Font* getFont() { return _font.get(); }
57
59 const Font* getFont() const { return _font.get(); }
60
61
63 void setStyle(Style* style) { _style = style; }
65 Style* getStyle() { return _style.get(); }
67 const Style* getStyle() const { return _style.get(); }
68
70 Style* getOrCreateStyle() { if (!_style) _style = new Style; return _style.get(); }
71
75 void setFontResolution(unsigned int width, unsigned int height);
76
77 unsigned int getFontWidth() const { return _fontSize.first; }
78 unsigned int getFontHeight() const { return _fontSize.second; }
79
80
82 void setText(const String& text);
83
86 void setText(const std::string& text);
87
90 void setText(const std::string& text,String::Encoding encoding);
91
94 void setText(const wchar_t* text);
95
99 String& getText() { return _text; }
100
102 const String& getText() const { return _text; }
103
107
108
110 void setCharacterSize(float height);
111
113 void setCharacterSize(float height, float aspectRatio);
114
115 float getCharacterHeight() const { return _characterHeight; }
116 float getCharacterAspectRatio() const { return _style.valid()? _style->getWidthRatio() : 1.0f; }
117
124
127
130
131
136 void setMaximumWidth(float maximumWidth);
137
139 float getMaximumWidth() const { return _maximumWidth; }
140
145 void setMaximumHeight(float maximumHeight);
146
148 float getMaximumHeight() const { return _maximumHeight; }
149
154 void setLineSpacing(float lineSpacing);
155
157 float getLineSpacing() const { return _lineSpacing; }
158
159
160
162 void setPosition(const osg::Vec3& pos);
163
165 const osg::Vec3& getPosition() const { return _position; }
166
167
193
196
197
209
212
213 void setRotation(const osg::Quat& quat);
214 const osg::Quat& getRotation() const { return _rotation; }
215
216 void setAutoRotateToScreen(bool autoRotateToScreen);
218
225
226 void setLayout(Layout layout);
227
228 Layout getLayout() const { return _layout; }
229
230
238
239 void setDrawMode(unsigned int mode);
240
241 unsigned int getDrawMode() const { return _drawMode; }
242
243 void setBoundingBoxMargin(float margin);
244
245 float getBoundingBoxMargin() const { return _textBBMargin; }
246
247 void setBoundingBoxColor(const osg::Vec4& color){ _textBBColor = color; }
248
249 const osg::Vec4& getBoundingBoxColor() const { return _textBBColor; }
250
251
252 void setKerningType(KerningType kerningType) { _kerningType = kerningType; }
253
255
257 unsigned int getLineCount() const { return _lineCount; }
258
262 virtual void compileGLObjects(osg::RenderInfo& renderInfo) const;
263
265 virtual void resizeGLObjectBuffers(unsigned int maxSize);
266
270 virtual void releaseGLObjects(osg::State* state=0) const;
271
272
274
276 Coords& getCoords() { return _coords; }
277 const Coords& getCoords() const { return _coords; }
278
279 void getCoord(unsigned int i, osg::Vec2& c) const { c.set((*_coords)[i].x(), (*_coords)[i].y()); }
280 void getCoord(unsigned int i, osg::Vec3& c) const { c = (*_coords)[i]; }
281
283 const osg::Matrix& getMatrix() const { return _matrix; }
284
286 bool computeMatrix(osg::Matrix& matrix, osg::State* state=0) const;
287
288protected:
289
290 virtual ~TextBase();
291
293
294 virtual void assignStateSet();
295
297
299
300 void positionCursor(const osg::Vec2 & endOfLine_coords, osg::Vec2 & cursor, unsigned int linelength);
301 String::iterator computeLastCharacterOnLine(osg::Vec2& cursor, String::iterator first,String::iterator last);
304
305 virtual void computeGlyphRepresentation() = 0;
306
309 typedef std::vector< osg::ref_ptr<osg::DrawElements> > Primitives;
310
311
312 // members which have public access.
323
331 unsigned int _drawMode;
335 unsigned int _lineCount;
337
342
344
346
348
351
356
357 unsigned int addCoord(const osg::Vec2& c) { unsigned int s = _coords->size(); _coords->push_back(osg::Vec3(c.x(), c.y(), 0.0f)); _coords->dirty(); return s; }
358 unsigned int addCoord(const osg::Vec3& c) { unsigned int s = _coords->size(); _coords->push_back(c); _coords->dirty(); return s; }
359
360
361 void addTexCoord(const osg::Vec2& tc) { _texcoords->push_back(tc); _texcoords->dirty(); }
362
363};
364
365}
366
367
368#endif
369
Vec2f Vec2
Definition Vec2:21
Vec3f Vec3
Definition Vec3:21
BoundingBoxd BoundingBox
Definition BoundingBox:257
Matrixd Matrix
Definition Matrix:27
Vec4f Vec4
Definition Vec4:21
The osgText library is a NodeKit that extends the core scene graph to support high quality text.
std::pair< unsigned int, unsigned int > FontResolution
Definition KerningType:20
KerningType
Definition KerningType:23
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Pure virtual base class for drawable geometry.
Definition Drawable:89
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
A quaternion class.
Definition Quat:30
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Definition RenderInfo:28
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
Stores a set of modes and attributes which represent a set of OpenGL state.
Definition StateSet:46
void set(value_type x, value_type y)
Definition Vec2f:61
value_type & x()
Definition Vec2f:67
value_type & y()
Definition Vec2f:68
Definition VertexArrayState:25
Pure virtual base class for fonts.
Definition Font:68
Definition String:44
Encoding
Types of string encodings supported.
Definition String:53
Definition Style:72
void setRotation(const osg::Quat &quat)
osg::ref_ptr< Style > _style
Definition TextBase:316
KerningType _kerningType
Definition TextBase:334
AlignmentType
Definition TextBase:169
@ CENTER_CENTER
Definition TextBase:175
@ LEFT_CENTER
Definition TextBase:171
@ LEFT_BASE_LINE
Definition TextBase:182
@ RIGHT_BASE_LINE
Definition TextBase:184
@ RIGHT_BOTTOM
Definition TextBase:180
@ RIGHT_TOP
Definition TextBase:178
@ LEFT_TOP
Definition TextBase:170
@ LEFT_BOTTOM
Definition TextBase:172
@ CENTER_TOP
Definition TextBase:174
@ LEFT_BOTTOM_BASE_LINE
Definition TextBase:186
@ CENTER_BOTTOM_BASE_LINE
Definition TextBase:187
@ BASE_LINE
Definition TextBase:190
@ CENTER_BASE_LINE
Definition TextBase:183
@ CENTER_BOTTOM
Definition TextBase:176
@ RIGHT_CENTER
Definition TextBase:179
@ RIGHT_BOTTOM_BASE_LINE
Definition TextBase:188
void update()
update internal glyph respresentation used for rendering, and bounding volume.
Definition TextBase:106
float _maximumWidth
Definition TextBase:320
bool getAutoRotateToScreen() const
Definition TextBase:217
float getCharacterHeight() const
Definition TextBase:115
osg::BoundingBox _textBBWithMargin
Definition TextBase:341
void getCoord(unsigned int i, osg::Vec3 &c) const
Definition TextBase:280
virtual void setFont(Font *font=0)
Set the Font to use to render the text.
Definition TextBase:45
Layout
Definition TextBase:220
@ VERTICAL
Definition TextBase:223
@ RIGHT_TO_LEFT
default
Definition TextBase:222
@ LEFT_TO_RIGHT
Definition TextBase:221
AxisAlignment
Definition TextBase:199
@ REVERSED_XY_PLANE
Definition TextBase:201
@ SCREEN
Definition TextBase:206
@ REVERSED_XZ_PLANE
Definition TextBase:203
@ YZ_PLANE
Definition TextBase:204
@ XY_PLANE
Definition TextBase:200
@ XZ_PLANE
Definition TextBase:202
@ USER_DEFINED_ROTATION
Definition TextBase:207
@ REVERSED_YZ_PLANE
Definition TextBase:205
float _textBBMargin
Definition TextBase:332
osg::ref_ptr< osg::VertexBufferObject > _vbo
Definition TextBase:349
const osg::Vec4 & getBoundingBoxColor() const
Definition TextBase:249
String & getText()
Get the text string.
Definition TextBase:99
float _maximumHeight
Definition TextBase:321
virtual void assignStateSet()
void setColor(const osg::Vec4 &color)
float getMaximumHeight() const
Get the maximum height of the text box.
Definition TextBase:148
osg::ref_ptr< osg::Vec3Array > Coords
Definition TextBase:275
virtual void setFont(const std::string &fontfile)
Set the font, loaded from the specified front file, to use to render the text, setFont("") sets the u...
CharacterSizeMode getCharacterSizeMode() const
Get the CharacterSizeMode.
Definition TextBase:129
Layout _layout
Definition TextBase:330
osg::Vec3 _position
Definition TextBase:325
const String & getText() const
Get the const text string.
Definition TextBase:102
unsigned int addCoord(const osg::Vec2 &c)
Definition TextBase:357
Style * getOrCreateStyle()
Get or create the text style.
Definition TextBase:70
bool _glyphNormalized
Definition TextBase:336
AlignmentType getAlignment() const
Definition TextBase:195
void setBoundingBoxColor(const osg::Vec4 &color)
Definition TextBase:247
virtual ~TextBase()
const Style * getStyle() const
Get the const text style.
Definition TextBase:67
void setAxisAlignment(AxisAlignment axis)
float getLineSpacing() const
Get the line spacing of the text box.
Definition TextBase:157
Coords & getCoords()
Definition TextBase:276
void setText(const std::string &text, String::Encoding encoding)
Set the text using a Unicode encoded std::string, which is converted to an internal TextString.
AxisAlignment _axisAlignment
Definition TextBase:327
unsigned int _drawMode
Definition TextBase:331
Coords _coords
Definition TextBase:352
osg::ref_ptr< Font > _fontFallback
Definition TextBase:315
void setAlignment(AlignmentType alignment)
virtual void releaseGLObjects(osg::State *state=0) const
If State is non-zero, this function releases OpenGL objects for the specified graphics context.
virtual void resizeGLObjectBuffers(unsigned int maxSize)
Resize any per context GLObject buffers to specified size.
virtual osg::BoundingBox computeBoundingBox() const
Compute the bounding box around Drawables's geometry.
virtual void compileGLObjects(osg::RenderInfo &renderInfo) const
Immediately compile this Drawable into an OpenGL Display List/VertexBufferObjects.
void setLayout(Layout layout)
osg::VertexArrayState * createVertexArrayStateImplementation(osg::RenderInfo &renderInfo) const
Implementation of Create the VertexArrayState object.
unsigned int _lineCount
Definition TextBase:335
osg::Vec4 _textBBColor
Definition TextBase:333
void setFontResolution(unsigned int width, unsigned int height)
Set the Font reference width and height resolution in texels.
float getMaximumWidth() const
Get the maximim width of the text box.
Definition TextBase:139
void setCharacterSizeMode(CharacterSizeMode mode)
Set how the CharacterSize value relates to the final rendered character.
Definition TextBase:126
float _characterHeight
Definition TextBase:318
void setLineSpacing(float lineSpacing)
Set the line spacing of the text box, given as a percentage of the character height.
Coords _normals
Definition TextBase:353
bool _autoRotateToScreen
Definition TextBase:329
ColorCoords _colorCoords
Definition TextBase:354
CharacterSizeMode
Definition TextBase:119
@ SCREEN_COORDS
default
Definition TextBase:121
@ OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT
internally scale the characters to be constant screen size.
Definition TextBase:122
@ OBJECT_COORDS
Definition TextBase:120
String::iterator computeLastCharacterOnLine(osg::Vec2 &cursor, String::iterator first, String::iterator last)
bool computeMatrix(osg::Matrix &matrix, osg::State *state=0) const
compute the matrix that positions the text in model space for the given viewpoint.
unsigned int addCoord(const osg::Vec3 &c)
Definition TextBase:358
void setCharacterSize(float height, float aspectRatio)
Set the rendered character size in object coordinates.
void setStyle(Style *style)
Set the text style.
Definition TextBase:63
virtual const char * className() const
return the name of the node's class type.
Definition TextBase:37
TextBase(const TextBase &text, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
void setCharacterSize(float height)
Set the rendered character size in object coordinates.
Primitives _decorationPrimitives
Definition TextBase:345
void setText(const std::string &text)
Set the text using a std::string, which is converted to an internal TextString.
Style * getStyle()
Get the text style.
Definition TextBase:65
TexCoords _texcoords
Definition TextBase:355
float getBoundingBoxMargin() const
Definition TextBase:245
void addTexCoord(const osg::Vec2 &tc)
Definition TextBase:361
osg::BoundingBox _textBB
Definition TextBase:340
KerningType getKerningType() const
Definition TextBase:254
void setKerningType(KerningType kerningType)
Definition TextBase:252
void setMaximumWidth(float maximumWidth)
Set the maximum width of the text box.
unsigned int getFontHeight() const
Definition TextBase:78
osg::Matrix _matrix
Definition TextBase:343
virtual bool isSameKindAs(const osg::Object *obj) const
return true if this and obj are of the same kind of object.
Definition TextBase:36
Layout getLayout() const
Definition TextBase:228
void setAutoRotateToScreen(bool autoRotateToScreen)
virtual osg::StateSet * createStateSet()
DrawModeMask
Definition TextBase:232
@ TEXT
Definition TextBase:233
@ FILLEDBOUNDINGBOX
Definition TextBase:235
@ BOUNDINGBOX
default
Definition TextBase:234
@ ALIGNMENT
Definition TextBase:236
void setBoundingBoxMargin(float margin)
osg::ref_ptr< osg::ElementBufferObject > _ebo
Definition TextBase:350
osg::Vec3 _normal
Definition TextBase:339
unsigned int getLineCount() const
Get the number of wrapped lines - only valid after computeGlyphRepresentation() has been called,...
Definition TextBase:257
osg::ref_ptr< Font > _font
Definition TextBase:314
float _lineSpacing
Definition TextBase:322
FontResolution _fontSize
Definition TextBase:317
Font * getFont()
Get the font.
Definition TextBase:56
AlignmentType _alignment
Definition TextBase:326
osg::Vec3 _offset
Definition TextBase:338
void setDrawMode(unsigned int mode)
void positionCursor(const osg::Vec2 &endOfLine_coords, osg::Vec2 &cursor, unsigned int linelength)
String _text
Definition TextBase:324
void getCoord(unsigned int i, osg::Vec2 &c) const
Definition TextBase:279
virtual const char * libraryName() const
return the name of the node's library.
Definition TextBase:38
unsigned int getDrawMode() const
Definition TextBase:241
osg::ref_ptr< osg::Vec2Array > TexCoords
Definition TextBase:307
void setText(const wchar_t *text)
Set the text using a wchar_t string, which is converted to an internal TextString.
osg::Quat _rotation
Definition TextBase:328
const osg::Vec4 & getColor() const
Definition TextBase:41
void setText(const String &text)
Set the text using a osgText::String.
CharacterSizeMode _characterSizeMode
Definition TextBase:319
const osg::Quat & getRotation() const
Definition TextBase:214
void setMaximumHeight(float maximumHeight)
Set the maximum height of the text box.
AxisAlignment getAxisAlignment() const
Definition TextBase:211
void setPosition(const osg::Vec3 &pos)
Set the position of text.
const osg::Matrix & getMatrix() const
Get the cached internal matrix used to provide positioning of text.
Definition TextBase:283
virtual void setFont(osg::ref_ptr< Font > font)
Set the Font to use to render the text.
void initArraysAndBuffers()
std::vector< osg::ref_ptr< osg::DrawElements > > Primitives
Definition TextBase:309
const Coords & getCoords() const
Definition TextBase:277
float getCharacterAspectRatio() const
Definition TextBase:116
osg::Vec4 _color
Definition TextBase:313
virtual void computeGlyphRepresentation()=0
virtual void computePositionsImplementation()
const Font * getFont() const
Get the const font.
Definition TextBase:59
unsigned int getFontWidth() const
Definition TextBase:77
const osg::Vec3 & getPosition() const
Get the position of text.
Definition TextBase:165
osg::ref_ptr< osg::Vec4Array > ColorCoords
Definition TextBase:308
#define NULL
Definition Export:55
#define OSGTEXT_EXPORT
Definition Export:39

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.