OpenSceneGraph 3.6.5
Text
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_TEXT
15#define OSGTEXT_TEXT 1
16
17
18#include <osg/Drawable>
19#include <osg/Quat>
20
21#include <osgText/TextBase>
22#include <osgText/Font>
23
24namespace osgText {
25
27{
28public:
29
31 Text(const Text& text,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
32
33 virtual osg::Object* cloneType() const { return new Text(); }
34 virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new Text(*this,copyop); }
35 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Text*>(obj)!=NULL; }
36 virtual const char* className() const { return "Text"; }
37 virtual const char* libraryName() const { return "osgText"; }
38
41
44
45
52 void setEnableDepthWrites(bool enable) { _enableDepthWrites = enable; }
54
55
69
86
88
105 void setBackdropOffset(float offset = 0.07f);
110 void setBackdropOffset(float horizontal, float vertical);
111
113
115
120 void setBackdropColor(const osg::Vec4& color);
121
122 const osg::Vec4& getBackdropColor() const { return _backdropColor; }
123
125 {
126 SOLID = 0, // a.k.a. ColorGradients off
129 };
130
149
151
157 void setColorGradientCorners(const osg::Vec4& topLeft, const osg::Vec4& bottomLeft, const osg::Vec4& bottomRight, const osg::Vec4& topRight);
158
163
164
165
167 virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
168
170 virtual bool supports(const osg::Drawable::AttributeFunctor&) const { return false; }
171
173 virtual bool supports(const osg::Drawable::ConstAttributeFunctor&) const { return true; }
174
177
179 virtual bool supports(const osg::PrimitiveFunctor&) const { return true; }
180
182 virtual void accept(osg::PrimitiveFunctor& pf) const;
183
184
186 bool getCharacterCorners(unsigned int index, osg::Vec3& bottomLeft, osg::Vec3& bottomRight, osg::Vec3& topLeft, osg::Vec3& topRight) const;
187
189 virtual void resizeGLObjectBuffers(unsigned int maxSize);
190
191
195 virtual void releaseGLObjects(osg::State* state=0) const;
196
197public:
198
208
213
214 // internal structures, variable and methods used for rendering of characters.
216 {
217 typedef std::vector<Glyph*> Glyphs;
218
221
224
226
227 Glyphs& getGlyphs() { return _glyphs; }
228 const Glyphs& getGlyphs() const { return _glyphs; }
229
231 void resizeGLObjectBuffers(unsigned int maxSize);
232
236 void releaseGLObjects(osg::State* state=0) const;
237
238 private:
239
240 GlyphQuads& operator = (const GlyphQuads&) { return *this; }
241 };
242
243 typedef std::map<osg::ref_ptr<GlyphTexture>,GlyphQuads> TextureGlyphQuadMap;
244
246 const GlyphQuads* getGlyphQuads(GlyphTexture* texture) const
247 {
248 TextureGlyphQuadMap::const_iterator itGlyphQuad = _textureGlyphQuadMap.find(texture);
249 if (itGlyphQuad == _textureGlyphQuadMap.end()) return NULL;
250
251 return &itGlyphQuad->second;
252 }
253
258
259 void addGlyphQuad(Glyph* glyph, const osg::Vec2& minc, const osg::Vec2& maxc, const osg::Vec2& mintc, const osg::Vec2& maxtc);
260
261protected:
262
263 virtual ~Text();
264
266
268
269 String::iterator computeLastCharacterOnLine(osg::Vec2& cursor, String::iterator first,String::iterator last);
270
271 // members which have public access.
272
273 // iternal map used for rendering. Set up by the computeGlyphRepresentation() method.
275
277
278 // internal caches of the positioning of the text.
279
280 bool computeAverageGlyphWidthAndHeight(float& avg_width, float& avg_height) const;
281
283
287
288 void drawImplementation(osg::State& state, const osg::Vec4& colorMultiplier) const;
289
290 void drawImplementationSinglePass(osg::State& state, const osg::Vec4& colorMultiplier) const;
291
294
296
300
306
307
308 // Helper function for color interpolation
309 float bilinearInterpolate(float x1, float x2, float y1, float y2, float x, float y, float q11, float q12, float q21, float q22) const;
310};
311
312}
313
314
315#endif
Vec2f Vec2
Definition Vec2:21
Vec3f Vec3
Definition Vec3:21
Vec4f Vec4
Definition Vec4:21
The osgText library is a NodeKit that extends the core scene graph to support high quality text.
ShaderTechnique
Definition Glyph:42
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
Definition Drawable:426
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
A PrimitiveFunctor is used (in conjunction with osg::Drawable::accept (PrimitiveFunctor&)) to get acc...
Definition PrimitiveSet:54
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
Pure virtual base class for fonts.
Definition Font:68
Definition Glyph:50
Definition Glyph:257
ColorGradientMode getColorGradientMode() const
Definition Text:150
void setBackdropImplementation(BackdropImplementation)
deprecated, value ignored.
Definition Text:210
ColorGradientMode
Definition Text:125
@ SOLID
Definition Text:126
@ PER_CHARACTER
Definition Text:127
@ OVERALL
Definition Text:128
void computeGlyphRepresentation()
bool computeAverageGlyphWidthAndHeight(float &avg_width, float &avg_height) const
BackdropType
Definition Text:57
@ NONE
Definition Text:67
@ DROP_SHADOW_BOTTOM_CENTER
Definition Text:61
@ DROP_SHADOW_TOP_LEFT
Definition Text:65
@ DROP_SHADOW_CENTER_LEFT
Definition Text:64
@ DROP_SHADOW_BOTTOM_RIGHT
Definition Text:58
@ DROP_SHADOW_CENTER_RIGHT
Definition Text:59
@ DROP_SHADOW_BOTTOM_LEFT
Definition Text:63
@ OUTLINE
Definition Text:66
@ DROP_SHADOW_TOP_CENTER
Definition Text:62
@ DROP_SHADOW_TOP_RIGHT
Definition Text:60
void setBackdropType(BackdropType type)
BackdropType gives you a background shadow text behind your regular text.
ColorGradientMode _colorGradientMode
Definition Text:301
virtual const char * className() const
return the name of the node's class type.
Definition Text:36
const osg::Vec4 & getColorGradientBottomLeft() const
Definition Text:160
const osg::Vec4 & getColorGradientBottomRight() const
Definition Text:161
void setEnableDepthWrites(bool enable)
Turns off writing to the depth buffer when rendering text.
Definition Text:52
BackdropImplementation getBackdropImplementation() const
deprecated, value should be ignored.
Definition Text:212
void setBackdropColor(const osg::Vec4 &color)
This specifies the color of the backdrop text.
const osg::Vec4 & getColorGradientTopRight() const
Definition Text:162
virtual bool supports(const osg::PrimitiveFunctor &) const
return true, osgText::Text does support accept(PrimitiveFunctor&) .
Definition Text:179
void computeColorGradients()
virtual void accept(osg::PrimitiveFunctor &pf) const
accept a PrimtiveFunctor and call its methods to tell it about the internal primitives that this Draw...
BackdropType _backdropType
Definition Text:295
void drawImplementation(osg::State &state, const osg::Vec4 &colorMultiplier) const
void computeColorGradientsOverall()
virtual osg::Object * cloneType() const
clone an object of the same type as the node.
Definition Text:33
String::iterator computeLastCharacterOnLine(osg::Vec2 &cursor, String::iterator first, String::iterator last)
void setColorGradientCorners(const osg::Vec4 &topLeft, const osg::Vec4 &bottomLeft, const osg::Vec4 &bottomRight, const osg::Vec4 &topRight)
Used only for gradient mode, let's you specify the colors of the 4 corners.
float bilinearInterpolate(float x1, float x2, float y1, float y2, float x, float y, float q11, float q12, float q21, float q22) const
Text(const Text &text, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
virtual bool supports(const osg::Drawable::ConstAttributeFunctor &) const
return true, osgText::Text does support accept(ConstAttributeFunctor&).
Definition Text:173
float getBackdropVerticalOffset() const
Definition Text:114
void computeColorGradientsPerCharacter()
void setBackdropOffset(float horizontal, float vertical)
This overloaded version lets you specify the offset for the horizontal and vertical components separa...
float _backdropHorizontalOffset
Definition Text:297
const GlyphQuads * getGlyphQuads(GlyphTexture *texture) const
Direct Access to GlyphQuads.
Definition Text:246
virtual void computePositionsImplementation()
float _backdropVerticalOffset
Definition Text:298
ShaderTechnique getShaderTechnique()
Get the ShaderTechnique hint.
Definition Text:43
BackdropImplementation
deprecated, value ignored.
Definition Text:201
@ DELAYED_DEPTH_WRITES
Definition Text:206
@ STENCIL_BUFFER
Definition Text:205
@ POLYGON_OFFSET
Definition Text:202
@ NO_DEPTH_BUFFER
Definition Text:203
@ DEPTH_RANGE
Definition Text:204
virtual void releaseGLObjects(osg::State *state=0) const
If State is non-zero, this function releases OpenGL objects for the specified graphics context.
virtual bool supports(const osg::Drawable::AttributeFunctor &) const
return false, osgText::Text does not support accept(AttributeFunctor&).
Definition Text:170
osg::Vec4 _colorGradientTopRight
Definition Text:305
ShaderTechnique _shaderTechnique
Definition Text:292
bool _enableDepthWrites
Definition Text:293
TextureGlyphQuadMap _textureGlyphQuadMap
Definition Text:274
virtual void accept(osg::Drawable::ConstAttributeFunctor &af) const
accept an ConstAttributeFunctor and call its methods to tell it about the internal attributes that th...
virtual ~Text()
virtual void resizeGLObjectBuffers(unsigned int maxSize)
Resize any per context GLObject buffers to specified size.
float getBackdropHorizontalOffset() const
Definition Text:112
virtual bool isSameKindAs(const osg::Object *obj) const
return true if this and obj are of the same kind of object.
Definition Text:35
std::map< osg::ref_ptr< GlyphTexture >, GlyphQuads > TextureGlyphQuadMap
Definition Text:243
const TextureGlyphQuadMap & getTextureGlyphQuadMap() const
Definition Text:254
virtual osg::StateSet * createStateSet()
void setColorGradientMode(ColorGradientMode mode)
This sets different types of text coloring modes.
virtual void drawImplementation(osg::RenderInfo &renderInfo) const
Draw the text.
osg::Vec4 _colorGradientTopLeft
Definition Text:302
const osg::Vec4 & getBackdropColor() const
Definition Text:122
virtual osg::Object * clone(const osg::CopyOp &copyop) const
return a clone of a node, with Object* return type.
Definition Text:34
Font * getActiveFont()
virtual const char * libraryName() const
return the name of the node's library.
Definition Text:37
void drawImplementationSinglePass(osg::State &state, const osg::Vec4 &colorMultiplier) const
osg::Vec4 _backdropColor
Definition Text:299
osg::Vec4 _colorGradientBottomRight
Definition Text:304
const osg::Vec4 & getColorGradientTopLeft() const
Definition Text:159
bool getEnableDepthWrites() const
Definition Text:53
void addGlyphQuad(Glyph *glyph, const osg::Vec2 &minc, const osg::Vec2 &maxc, const osg::Vec2 &mintc, const osg::Vec2 &maxtc)
bool getCharacterCorners(unsigned int index, osg::Vec3 &bottomLeft, osg::Vec3 &bottomRight, osg::Vec3 &topLeft, osg::Vec3 &topRight) const
Get the coordinates of the character corners in local coordinates.
void setBackdropOffset(float offset=0.07f)
Sets the amount text is offset to create the backdrop/shadow effect.
void setShaderTechnique(ShaderTechnique technique)
Set the ShaderTechnique hint to specify what fatures in the text shaders to enable.
BackdropType getBackdropType() const
Definition Text:87
osg::Vec4 _colorGradientBottomLeft
Definition Text:303
Definition Text:216
void releaseGLObjects(osg::State *state=0) const
If State is non-zero, this function releases OpenGL objects for the specified graphics context.
Glyphs & getGlyphs()
Definition Text:227
const Glyphs & getGlyphs() const
Definition Text:228
void setupPrimitives(Text::BackdropType backdropType)
void resizeGLObjectBuffers(unsigned int maxSize)
Resize any per context GLObject buffers to specified size.
std::vector< Glyph * > Glyphs
Definition Text:217
GlyphQuads(const GlyphQuads &gq)
Glyphs _glyphs
Definition Text:219
osg::ref_ptr< osg::DrawElements > _primitives
Definition Text:220
Definition TextBase:28
#define NULL
Definition Export:55
#define OSGTEXT_EXPORT
Definition Export:39

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.