OpenSceneGraph 3.6.5
Glyph
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 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_GLYPH
15#define OSGTEXT_GLYPH 1
16
17#include <string>
18#include <istream>
19
20#include <osg/Vec2>
21#include <osg/Image>
22#include <osg/Texture2D>
23#include <osg/StateSet>
24#include <osg/Geometry>
25#include <osg/Geode>
26
27#include <osgText/Export>
28#include <osgText/KerningType>
29#include <osgText/Style>
30
31#include <OpenThreads/ReentrantMutex>
32
33namespace osgText {
34
35class Font;
36class Text;
37class Glyph3D;
38class GlyphGeometry;
39class GlyphTexture;
40
48
50{
51public:
52
53 Glyph(Font* font, unsigned int glyphCode);
54
55 Font* getFont() { return _font; }
56 const Font* getFont() const { return _font; }
57
58 unsigned int getGlyphCode() const { return _glyphCode; }
59
60 void setFontResolution(const FontResolution& fontRes) { _fontResolution = fontRes; }
62
63 void setWidth(float width) { _width = width; }
64 float getWidth() const { return _width; }
65
66 void setHeight(float height) { _height = height; }
67 float getHeight() const { return _height; }
68
69 void setHorizontalBearing(const osg::Vec2& bearing);
71
72 void setHorizontalAdvance(float advance);
73 float getHorizontalAdvance() const;
74
75 void setVerticalBearing(const osg::Vec2& bearing);
77
78 void setVerticalAdvance(float advance);
79 float getVerticalAdvance() const;
80
82 {
84 texture(0),
85 texelMargin(0.0f) {}
86
87 TextureInfo(GlyphTexture* tex, int x, int y, const osg::Vec2& mintc, const osg::Vec2& maxtc, float margin):
88 texture(tex),
91 minTexCoord(mintc),
92 maxTexCoord(maxtc),
93 texelMargin(margin) {}
94
101 };
102
104
106
108
109protected:
110
111 virtual ~Glyph();
112
114 unsigned int _glyphCode;
115
117
118 float _width;
119 float _height;
120
123
126
127 typedef std::vector< osg::ref_ptr<TextureInfo> > TextureInfoList;
129
130 mutable OpenThreads::ReentrantMutex _textureInfoListMutex;
131};
132
178
179
181{
182public:
183
184 Glyph3D(Font* font, unsigned int glyphCode);
185
186 Font* getFont() { return _font; }
187 const Font* getFont() const { return _font; }
188
189 unsigned int getGlyphCode() const { return _glyphCode; }
190
191 void setWidth(float width) { _width = width; }
192 float getWidth() const { return _width; }
193
194 void setHeight(float height) { _height = height; }
195 float getHeight() const { return _height; }
196
197 void setHorizontalBearing(const osg::Vec2& bearing) { _horizontalBearing=bearing; }
199
200 void setHorizontalAdvance(float advance) { _horizontalAdvance=advance; }
201 float getHorizontalAdvance() const { return _horizontalAdvance; }
202
203 void setVerticalBearing(const osg::Vec2& bearing) { _verticalBearing=bearing; }
205
206 void setVerticalAdvance(float advance) { _verticalAdvance=advance; }
207 float getVerticalAdvance() const { return _verticalAdvance; }
208
210 const osg::BoundingBox & getBoundingBox() const { return _bb; }
211
212
214 virtual void setThreadSafeRefUnref(bool threadSafe);
215
216
217 void setRawVertexArray(osg::Vec3Array* vertices) { _rawVertexArray = vertices; }
219 const osg::Vec3Array* getRawVertexArray() const { return _rawVertexArray.get(); }
220
224
226
227protected:
228
229 virtual ~Glyph3D() {}
230
232 unsigned int _glyphCode;
233
234 float _width;
235 float _height;
236
239
242
244// osg::Vec2 _advance;
245
246
249
250 typedef std::list< osg::ref_ptr<GlyphGeometry> > GlyphGeometries;
252
253};
254
255
257{
258public:
259
261
262 const char* className() const { return "GlyphTexture"; }
263
265 virtual int compare(const osg::StateAttribute& rhs) const;
266
267 void setShaderTechnique(ShaderTechnique technique) { _shaderTechnique = technique; }
268
270
271
272 int getEffectMargin(const Glyph* glyph);
273 int getTexelMargin(const Glyph* glyph);
274
275 bool getSpaceForGlyph(Glyph* glyph, int& posX, int& posY);
276
277 void addGlyph(Glyph* glyph,int posX, int posY);
278
280 virtual void setThreadSafeRefUnref(bool threadSafe);
281
283 virtual void resizeGLObjectBuffers(unsigned int maxSize);
284
287
288protected:
289
290 virtual ~GlyphTexture();
291
293
295
299
300 typedef std::vector< osg::ref_ptr<Glyph> > GlyphRefList;
301 typedef std::vector< const Glyph* > GlyphPtrList;
303
306
307 mutable OpenThreads::Mutex _mutex;
308
309};
310
311}
312
313
314#endif
Vec2f Vec2
Definition Vec2:21
TemplateArray< Vec3, Array::Vec3ArrayType, 3, GL_FLOAT > Vec3Array
Definition Array:449
BoundingBoxd BoundingBox
Definition BoundingBox:257
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
ShaderTechnique
Definition Glyph:42
@ SIGNED_DISTANCE_FIELD
Definition Glyph:45
@ ALL_FEATURES
Definition Glyph:46
@ GREYSCALE
Definition Glyph:44
@ NO_TEXT_SHADER
Definition Glyph:43
A Geode is a "geometry node", that is, a leaf node on the scene graph that can have "renderable thing...
Definition Geode:29
Definition Geometry:31
std::vector< ref_ptr< PrimitiveSet > > PrimitiveSetList
Definition Geometry:102
Image class for encapsulating the storage texture image data.
Definition Image:179
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Base class for providing reference counted objects.
Definition Referenced:44
Base class for state attributes.
Definition StateAttribute:77
Encapsulates OpenGL 2D texture functionality.
Definition Texture2D:25
Pure virtual base class for fonts.
Definition Font:68
Definition Glyph:50
Font * getFont()
Definition Glyph:55
OpenThreads::ReentrantMutex _textureInfoListMutex
Definition Glyph:130
unsigned int _glyphCode
Definition Glyph:114
float _height
Definition Glyph:119
TextureInfoList _textureInfoList
Definition Glyph:128
void setHorizontalAdvance(float advance)
float _verticalAdvance
Definition Glyph:125
const Font * getFont() const
Definition Glyph:56
float _horizontalAdvance
Definition Glyph:122
float _width
Definition Glyph:118
const osg::Vec2 & getHorizontalBearing() const
void setFontResolution(const FontResolution &fontRes)
Definition Glyph:60
Glyph(Font *font, unsigned int glyphCode)
void setTextureInfo(ShaderTechnique technique, TextureInfo *info)
void setVerticalBearing(const osg::Vec2 &bearing)
osg::Vec2 _verticalBearing
Definition Glyph:124
unsigned int getGlyphCode() const
Definition Glyph:58
const TextureInfo * getTextureInfo(ShaderTechnique technique) const
TextureInfo * getOrCreateTextureInfo(ShaderTechnique technique)
void setHorizontalBearing(const osg::Vec2 &bearing)
float getVerticalAdvance() const
FontResolution _fontResolution
Definition Glyph:116
osg::Vec2 _horizontalBearing
Definition Glyph:121
std::vector< osg::ref_ptr< TextureInfo > > TextureInfoList
Definition Glyph:127
const FontResolution & getFontResolution() const
Definition Glyph:61
const osg::Vec2 & getVerticalBearing() const
float getHeight() const
Definition Glyph:67
void setHeight(float height)
Definition Glyph:66
Font * _font
Definition Glyph:113
float getWidth() const
Definition Glyph:64
float getHorizontalAdvance() const
void setWidth(float width)
Definition Glyph:63
virtual ~Glyph()
void setVerticalAdvance(float advance)
Definition Glyph:82
osg::Vec2 minTexCoord
Definition Glyph:98
GlyphTexture * texture
Definition Glyph:95
TextureInfo()
Definition Glyph:83
float texelMargin
Definition Glyph:100
int texturePositionX
Definition Glyph:96
osg::Vec2 maxTexCoord
Definition Glyph:99
int texturePositionY
Definition Glyph:97
TextureInfo(GlyphTexture *tex, int x, int y, const osg::Vec2 &mintc, const osg::Vec2 &maxtc, float margin)
Definition Glyph:87
Definition Glyph:134
osg::ref_ptr< osg::Geode > _geode
Definition Glyph:169
void setVertexArray(osg::Vec3Array *va)
Set the VertexArray of the glyph.
Definition Glyph:147
osg::ref_ptr< Style > _style
Definition Glyph:168
bool match(const Style *style) const
osg::ref_ptr< osg::Vec3Array > _vertices
Definition Glyph:171
osg::Geometry::PrimitiveSetList & getBackPrimitiveSetList()
Get et the PrimitiveSetList for the back face.
Definition Glyph:161
void setup(const Glyph3D *glyph, const Style *style)
osg::Geometry::PrimitiveSetList _wallPrimitiveSetList
Definition Glyph:175
osg::Vec3Array * getVertexArray() const
Get the VertexArray of the glyph.
Definition Glyph:149
osg::Geometry::PrimitiveSetList _backPrimitiveSetList
Definition Glyph:176
osg::ref_ptr< osg::Geometry > _geometry
Definition Glyph:170
osg::Geometry::PrimitiveSetList _frontPrimitiveSetList
Definition Glyph:174
osg::Geometry::PrimitiveSetList & getFrontPrimitiveSetList()
Get the PrimitiveSetList for the front face.
Definition Glyph:157
osg::Geometry * getGeometry() const
Definition Glyph:144
osg::ref_ptr< osg::Vec3Array > _normals
Definition Glyph:172
void setNormalArray(osg::Vec3Array *na)
Set the VertexArray of the glyph.
Definition Glyph:152
virtual void setThreadSafeRefUnref(bool threadSafe)
Set whether to use a mutex to ensure ref() and unref() are thread safe.
osg::Geometry::PrimitiveSetList & getWallPrimitiveSetList()
Get the PrimitiveSetList for the wall face.
Definition Glyph:159
osg::Vec3Array * getNormalArray() const
Get the NormalArray for the wall face.
Definition Glyph:154
osg::Geode * getGeode() const
Definition Glyph:143
Definition Glyph:181
GlyphGeometries _glyphGeometries
Definition Glyph:251
const osg::Vec3Array * getRawVertexArray() const
Definition Glyph:219
const osg::Geometry::PrimitiveSetList & getRawFacePrimitiveSetList() const
Definition Glyph:223
std::list< osg::ref_ptr< GlyphGeometry > > GlyphGeometries
Definition Glyph:250
float _horizontalAdvance
Definition Glyph:238
Font * _font
Definition Glyph:231
osg::BoundingBox _bb
Definition Glyph:243
void setWidth(float width)
Definition Glyph:191
osg::Geometry::PrimitiveSetList & getRawFacePrimitiveSetList()
Get the PrimitiveSetList for the raw face which hasn't been tessellated.
Definition Glyph:222
void setBoundingBox(osg::BoundingBox &bb)
Definition Glyph:209
Font * getFont()
Definition Glyph:186
virtual void setThreadSafeRefUnref(bool threadSafe)
Set whether to use a mutex to ensure ref() and unref() are thread safe.
void setVerticalAdvance(float advance)
Definition Glyph:206
osg::Vec2 _verticalBearing
Definition Glyph:240
GlyphGeometry * getGlyphGeometry(const Style *style)
void setHorizontalBearing(const osg::Vec2 &bearing)
Definition Glyph:197
void setRawVertexArray(osg::Vec3Array *vertices)
Definition Glyph:217
float _height
Definition Glyph:235
float _width
Definition Glyph:234
float _verticalAdvance
Definition Glyph:241
void setVerticalBearing(const osg::Vec2 &bearing)
Definition Glyph:203
void setHeight(float height)
Definition Glyph:194
const osg::BoundingBox & getBoundingBox() const
Definition Glyph:210
unsigned int _glyphCode
Definition Glyph:232
osg::Vec2 _horizontalBearing
Definition Glyph:237
float getVerticalAdvance() const
Definition Glyph:207
float getHorizontalAdvance() const
Definition Glyph:201
unsigned int getGlyphCode() const
Definition Glyph:189
virtual ~Glyph3D()
Definition Glyph:229
float getWidth() const
Definition Glyph:192
float getHeight() const
Definition Glyph:195
Glyph3D(Font *font, unsigned int glyphCode)
const osg::Vec2 & getHorizontalBearing() const
Definition Glyph:198
void setHorizontalAdvance(float advance)
Definition Glyph:200
osg::Geometry::PrimitiveSetList _rawFacePrimitiveSetList
Definition Glyph:248
const Font * getFont() const
Definition Glyph:187
osg::ref_ptr< osg::Vec3Array > _rawVertexArray
Definition Glyph:247
osg::Vec3Array * getRawVertexArray()
Definition Glyph:218
const osg::Vec2 & getVerticalBearing() const
Definition Glyph:204
Definition Glyph:257
void addGlyph(Glyph *glyph, int posX, int posY)
virtual int compare(const osg::StateAttribute &rhs) const
return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.
std::vector< const Glyph * > GlyphPtrList
Definition Glyph:301
GlyphRefList _glyphs
Definition Glyph:304
ShaderTechnique _shaderTechnique
Definition Glyph:294
int _partUsedX
Definition Glyph:297
int getTexelMargin(const Glyph *glyph)
virtual void resizeGLObjectBuffers(unsigned int maxSize)
Resize any per context GLObject buffers to specified size.
GlyphBuffer _glyphsToSubload
Definition Glyph:305
virtual void setThreadSafeRefUnref(bool threadSafe)
Set whether to use a mutex to ensure ref() and unref() are thread safe.
int getEffectMargin(const Glyph *glyph)
osg::Image * createImage()
create an image that maps all the associated Glyph's onto a single image, that is equivalent to what ...
void copyGlyphImage(Glyph *glyph, Glyph::TextureInfo *info)
int _partUsedY
Definition Glyph:298
const char * className() const
Return the name of the attribute's class type.
Definition Glyph:262
void setShaderTechnique(ShaderTechnique technique)
Definition Glyph:267
osg::buffered_object< GlyphPtrList > GlyphBuffer
Definition Glyph:302
ShaderTechnique getShaderTechnique() const
Definition Glyph:269
bool getSpaceForGlyph(Glyph *glyph, int &posX, int &posY)
std::vector< osg::ref_ptr< Glyph > > GlyphRefList
Definition Glyph:300
OpenThreads::Mutex _mutex
Definition Glyph:307
int _usedY
Definition Glyph:296
Definition Style:72
#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.