Text
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGTEXT_TEXT
#define OSGTEXT_TEXT 1
#include <osg/Drawable>
#include <osg/Quat>
#include <osgText/TextBase>
#include <osgText/Font>
namespace osgText {
class OSGTEXT_EXPORT Text : public osgText::TextBase
{
public:
Text();
Text(const Text& text,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
virtual osg::Object* cloneType() const { return new Text(); }
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new Text(*this,copyop); }
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Text*>(obj)!=NULL; }
virtual const char* className() const { return "Text"; }
virtual const char* libraryName() const { return "osgText"; }
void setShaderTechnique(ShaderTechnique technique);
ShaderTechnique getShaderTechnique() { return _shaderTechnique; }
void setEnableDepthWrites(bool enable) { _enableDepthWrites = enable; }
bool getEnableDepthWrites() const { return _enableDepthWrites; }
enum BackdropType
{
DROP_SHADOW_BOTTOM_RIGHT = 0, // usually the type of shadow you see
DROP_SHADOW_CENTER_RIGHT,
DROP_SHADOW_TOP_RIGHT,
DROP_SHADOW_BOTTOM_CENTER,
DROP_SHADOW_TOP_CENTER,
DROP_SHADOW_BOTTOM_LEFT,
DROP_SHADOW_CENTER_LEFT,
DROP_SHADOW_TOP_LEFT,
OUTLINE,
NONE
};
void setBackdropType(BackdropType type);
BackdropType getBackdropType() const { return _backdropType; }
void setBackdropOffset(float offset = 0.07f);
void setBackdropOffset(float horizontal, float vertical);
float getBackdropHorizontalOffset() const { return _backdropHorizontalOffset; }
float getBackdropVerticalOffset() const { return _backdropVerticalOffset; }
void setBackdropColor(const osg::Vec4& color);
const osg::Vec4& getBackdropColor() const { return _backdropColor; }
enum ColorGradientMode
{
SOLID = 0, // a.k.a. ColorGradients off
PER_CHARACTER,
OVERALL
};
void setColorGradientMode(ColorGradientMode mode);
ColorGradientMode getColorGradientMode() const { return _colorGradientMode; }
void setColorGradientCorners(const osg::Vec4& topLeft, const osg::Vec4& bottomLeft, const osg::Vec4& bottomRight, const osg::Vec4& topRight);
const osg::Vec4& getColorGradientTopLeft() const { return _colorGradientTopLeft; }
const osg::Vec4& getColorGradientBottomLeft() const { return _colorGradientBottomLeft; }
const osg::Vec4& getColorGradientBottomRight() const { return _colorGradientBottomRight; }
const osg::Vec4& getColorGradientTopRight() const { return _colorGradientTopRight; }
virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
virtual bool supports(const osg::Drawable::AttributeFunctor&) const { return false; }
virtual bool supports(const osg::Drawable::ConstAttributeFunctor&) const { return true; }
virtual void accept(osg::Drawable::ConstAttributeFunctor& af) const;
virtual bool supports(const osg::PrimitiveFunctor&) const { return true; }
virtual void accept(osg::PrimitiveFunctor& pf) const;
bool getCharacterCorners(unsigned int index, osg::Vec3& bottomLeft, osg::Vec3& bottomRight, osg::Vec3& topLeft, osg::Vec3& topRight) const;
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* state=0) const;
public:
enum BackdropImplementation
{
POLYGON_OFFSET = 0,
NO_DEPTH_BUFFER,
DEPTH_RANGE,
STENCIL_BUFFER,
DELAYED_DEPTH_WRITES
};
void setBackdropImplementation(BackdropImplementation) {}
BackdropImplementation getBackdropImplementation() const { return DELAYED_DEPTH_WRITES; }
// internal structures, variable and methods used for rendering of characters.
struct OSGTEXT_EXPORT GlyphQuads
{
typedef std::vector<Glyph*> Glyphs;
Glyphs _glyphs;
osg::ref_ptr<osg::DrawElements> _primitives;
GlyphQuads();
GlyphQuads(const GlyphQuads& gq);
void setupPrimitives(Text::BackdropType backdropType);
Glyphs& getGlyphs() { return _glyphs; }
const Glyphs& getGlyphs() const { return _glyphs; }
void resizeGLObjectBuffers(unsigned int maxSize);
void releaseGLObjects(osg::State* state=0) const;
private:
GlyphQuads& operator = (const GlyphQuads&) { return *this; }
};
typedef std::map<osg::ref_ptr<GlyphTexture>,GlyphQuads> TextureGlyphQuadMap;
const GlyphQuads* getGlyphQuads(GlyphTexture* texture) const
{
TextureGlyphQuadMap::const_iterator itGlyphQuad = _textureGlyphQuadMap.find(texture);
if (itGlyphQuad == _textureGlyphQuadMap.end()) return NULL;
return &itGlyphQuad->second;
}
const TextureGlyphQuadMap& getTextureGlyphQuadMap() const
{
return _textureGlyphQuadMap;
}
void addGlyphQuad(Glyph* glyph, const osg::Vec2& minc, const osg::Vec2& maxc, const osg::Vec2& mintc, const osg::Vec2& maxtc);
protected:
virtual ~Text();
virtual osg::StateSet* createStateSet();
Font* getActiveFont();
String::iterator computeLastCharacterOnLine(osg::Vec2& cursor, String::iterator first,String::iterator last);
// members which have public access.
// iternal map used for rendering. Set up by the computeGlyphRepresentation() method.
TextureGlyphQuadMap _textureGlyphQuadMap;
void computeGlyphRepresentation();
// internal caches of the positioning of the text.
bool computeAverageGlyphWidthAndHeight(float& avg_width, float& avg_height) const;
virtual void computePositionsImplementation();
void computeColorGradients();
void computeColorGradientsOverall();
void computeColorGradientsPerCharacter();
void drawImplementation(osg::State& state, const osg::Vec4& colorMultiplier) const;
void drawImplementationSinglePass(osg::State& state, const osg::Vec4& colorMultiplier) const;
ShaderTechnique _shaderTechnique;
bool _enableDepthWrites;
BackdropType _backdropType;
float _backdropHorizontalOffset;
float _backdropVerticalOffset;
osg::Vec4 _backdropColor;
ColorGradientMode _colorGradientMode;
osg::Vec4 _colorGradientTopLeft;
osg::Vec4 _colorGradientBottomLeft;
osg::Vec4 _colorGradientBottomRight;
osg::Vec4 _colorGradientTopRight;
// Helper function for color interpolation
float bilinearInterpolate(float x1, float x2, float y1, float y2, float x, float y, float q11, float q12, float q21, float q22) const;
};
}
#endif
Drawable
Font
Quat
TextBase
osgText::Font
Definition Font:68
osgText::GlyphTexture
Definition Glyph:257
osgText::Glyph
Definition Glyph:50
osgText::TextBase
Definition TextBase:28
osgText::Text::getColorGradientMode
ColorGradientMode getColorGradientMode() const
Definition Text:150
osgText::Text::setBackdropImplementation
void setBackdropImplementation(BackdropImplementation)
Definition Text:210
osgText::Text::ColorGradientMode
ColorGradientMode
Definition Text:125
osgText::Text::SOLID
@ SOLID
Definition Text:126
osgText::Text::PER_CHARACTER
@ PER_CHARACTER
Definition Text:127
osgText::Text::OVERALL
@ OVERALL
Definition Text:128
osgText::Text::computeGlyphRepresentation
void computeGlyphRepresentation()
osgText::Text::computeAverageGlyphWidthAndHeight
bool computeAverageGlyphWidthAndHeight(float &avg_width, float &avg_height) const
osgText::Text::BackdropType
BackdropType
Definition Text:57
osgText::Text::NONE
@ NONE
Definition Text:67
osgText::Text::DROP_SHADOW_BOTTOM_CENTER
@ DROP_SHADOW_BOTTOM_CENTER
Definition Text:61
osgText::Text::DROP_SHADOW_TOP_LEFT
@ DROP_SHADOW_TOP_LEFT
Definition Text:65
osgText::Text::DROP_SHADOW_CENTER_LEFT
@ DROP_SHADOW_CENTER_LEFT
Definition Text:64
osgText::Text::DROP_SHADOW_BOTTOM_RIGHT
@ DROP_SHADOW_BOTTOM_RIGHT
Definition Text:58
osgText::Text::DROP_SHADOW_CENTER_RIGHT
@ DROP_SHADOW_CENTER_RIGHT
Definition Text:59
osgText::Text::DROP_SHADOW_BOTTOM_LEFT
@ DROP_SHADOW_BOTTOM_LEFT
Definition Text:63
osgText::Text::OUTLINE
@ OUTLINE
Definition Text:66
osgText::Text::DROP_SHADOW_TOP_CENTER
@ DROP_SHADOW_TOP_CENTER
Definition Text:62
osgText::Text::DROP_SHADOW_TOP_RIGHT
@ DROP_SHADOW_TOP_RIGHT
Definition Text:60
osgText::Text::setBackdropType
void setBackdropType(BackdropType type)
osgText::Text::_colorGradientMode
ColorGradientMode _colorGradientMode
Definition Text:301
osgText::Text::className
virtual const char * className() const
Definition Text:36
osgText::Text::getColorGradientBottomLeft
const osg::Vec4 & getColorGradientBottomLeft() const
Definition Text:160
osgText::Text::getColorGradientBottomRight
const osg::Vec4 & getColorGradientBottomRight() const
Definition Text:161
osgText::Text::setEnableDepthWrites
void setEnableDepthWrites(bool enable)
Definition Text:52
osgText::Text::Text
Text()
osgText::Text::getBackdropImplementation
BackdropImplementation getBackdropImplementation() const
Definition Text:212
osgText::Text::setBackdropColor
void setBackdropColor(const osg::Vec4 &color)
osgText::Text::getColorGradientTopRight
const osg::Vec4 & getColorGradientTopRight() const
Definition Text:162
osgText::Text::supports
virtual bool supports(const osg::PrimitiveFunctor &) const
Definition Text:179
osgText::Text::computeColorGradients
void computeColorGradients()
osgText::Text::accept
virtual void accept(osg::PrimitiveFunctor &pf) const
osgText::Text::_backdropType
BackdropType _backdropType
Definition Text:295
osgText::Text::drawImplementation
void drawImplementation(osg::State &state, const osg::Vec4 &colorMultiplier) const
osgText::Text::computeColorGradientsOverall
void computeColorGradientsOverall()
osgText::Text::cloneType
virtual osg::Object * cloneType() const
Definition Text:33
osgText::Text::computeLastCharacterOnLine
String::iterator computeLastCharacterOnLine(osg::Vec2 &cursor, String::iterator first, String::iterator last)
osgText::Text::setColorGradientCorners
void setColorGradientCorners(const osg::Vec4 &topLeft, const osg::Vec4 &bottomLeft, const osg::Vec4 &bottomRight, const osg::Vec4 &topRight)
osgText::Text::bilinearInterpolate
float bilinearInterpolate(float x1, float x2, float y1, float y2, float x, float y, float q11, float q12, float q21, float q22) const
osgText::Text::Text
Text(const Text &text, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osgText::Text::supports
virtual bool supports(const osg::Drawable::ConstAttributeFunctor &) const
Definition Text:173
osgText::Text::getBackdropVerticalOffset
float getBackdropVerticalOffset() const
Definition Text:114
osgText::Text::computeColorGradientsPerCharacter
void computeColorGradientsPerCharacter()
osgText::Text::setBackdropOffset
void setBackdropOffset(float horizontal, float vertical)
osgText::Text::_backdropHorizontalOffset
float _backdropHorizontalOffset
Definition Text:297
osgText::Text::getGlyphQuads
const GlyphQuads * getGlyphQuads(GlyphTexture *texture) const
Definition Text:246
osgText::Text::computePositionsImplementation
virtual void computePositionsImplementation()
osgText::Text::_backdropVerticalOffset
float _backdropVerticalOffset
Definition Text:298
osgText::Text::getShaderTechnique
ShaderTechnique getShaderTechnique()
Definition Text:43
osgText::Text::BackdropImplementation
BackdropImplementation
Definition Text:201
osgText::Text::DELAYED_DEPTH_WRITES
@ DELAYED_DEPTH_WRITES
Definition Text:206
osgText::Text::STENCIL_BUFFER
@ STENCIL_BUFFER
Definition Text:205
osgText::Text::POLYGON_OFFSET
@ POLYGON_OFFSET
Definition Text:202
osgText::Text::NO_DEPTH_BUFFER
@ NO_DEPTH_BUFFER
Definition Text:203
osgText::Text::DEPTH_RANGE
@ DEPTH_RANGE
Definition Text:204
osgText::Text::releaseGLObjects
virtual void releaseGLObjects(osg::State *state=0) const
osgText::Text::supports
virtual bool supports(const osg::Drawable::AttributeFunctor &) const
Definition Text:170
osgText::Text::_colorGradientTopRight
osg::Vec4 _colorGradientTopRight
Definition Text:305
osgText::Text::_shaderTechnique
ShaderTechnique _shaderTechnique
Definition Text:292
osgText::Text::_enableDepthWrites
bool _enableDepthWrites
Definition Text:293
osgText::Text::_textureGlyphQuadMap
TextureGlyphQuadMap _textureGlyphQuadMap
Definition Text:274
osgText::Text::accept
virtual void accept(osg::Drawable::ConstAttributeFunctor &af) const
osgText::Text::~Text
virtual ~Text()
osgText::Text::resizeGLObjectBuffers
virtual void resizeGLObjectBuffers(unsigned int maxSize)
osgText::Text::getBackdropHorizontalOffset
float getBackdropHorizontalOffset() const
Definition Text:112
osgText::Text::isSameKindAs
virtual bool isSameKindAs(const osg::Object *obj) const
Definition Text:35
osgText::Text::TextureGlyphQuadMap
std::map< osg::ref_ptr< GlyphTexture >, GlyphQuads > TextureGlyphQuadMap
Definition Text:243
osgText::Text::getTextureGlyphQuadMap
const TextureGlyphQuadMap & getTextureGlyphQuadMap() const
Definition Text:254
osgText::Text::createStateSet
virtual osg::StateSet * createStateSet()
osgText::Text::setColorGradientMode
void setColorGradientMode(ColorGradientMode mode)
osgText::Text::drawImplementation
virtual void drawImplementation(osg::RenderInfo &renderInfo) const
osgText::Text::_colorGradientTopLeft
osg::Vec4 _colorGradientTopLeft
Definition Text:302
osgText::Text::getBackdropColor
const osg::Vec4 & getBackdropColor() const
Definition Text:122
osgText::Text::clone
virtual osg::Object * clone(const osg::CopyOp &copyop) const
Definition Text:34
osgText::Text::getActiveFont
Font * getActiveFont()
osgText::Text::libraryName
virtual const char * libraryName() const
Definition Text:37
osgText::Text::drawImplementationSinglePass
void drawImplementationSinglePass(osg::State &state, const osg::Vec4 &colorMultiplier) const
osgText::Text::_backdropColor
osg::Vec4 _backdropColor
Definition Text:299
osgText::Text::_colorGradientBottomRight
osg::Vec4 _colorGradientBottomRight
Definition Text:304
osgText::Text::getColorGradientTopLeft
const osg::Vec4 & getColorGradientTopLeft() const
Definition Text:159
osgText::Text::getEnableDepthWrites
bool getEnableDepthWrites() const
Definition Text:53
osgText::Text::addGlyphQuad
void addGlyphQuad(Glyph *glyph, const osg::Vec2 &minc, const osg::Vec2 &maxc, const osg::Vec2 &mintc, const osg::Vec2 &maxtc)
osgText::Text::getCharacterCorners
bool getCharacterCorners(unsigned int index, osg::Vec3 &bottomLeft, osg::Vec3 &bottomRight, osg::Vec3 &topLeft, osg::Vec3 &topRight) const
osgText::Text::setBackdropOffset
void setBackdropOffset(float offset=0.07f)
osgText::Text::setShaderTechnique
void setShaderTechnique(ShaderTechnique technique)
osgText::Text::getBackdropType
BackdropType getBackdropType() const
Definition Text:87
osgText::Text::_colorGradientBottomLeft
osg::Vec4 _colorGradientBottomLeft
Definition Text:303
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Drawable::AttributeFunctor
Definition Drawable:426
osg::Drawable::ConstAttributeFunctor
Definition Drawable:461
osg::Object
Definition Object:61
osg::PrimitiveFunctor
Definition PrimitiveSet:54
osg::RenderInfo
Definition RenderInfo:28
osg::StateSet
Definition StateSet:46
osg::State
Definition State:80
osg::ref_ptr
Definition ref_ptr:32
osgText
osgText::ShaderTechnique
ShaderTechnique
Definition Glyph:42
osg::Vec2
Vec2f Vec2
Definition Vec2:21
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osg::Vec4
Vec4f Vec4
Definition Vec4:21
OSGTEXT_EXPORT
#define OSGTEXT_EXPORT
Definition osgText/Export:39
NULL
#define NULL
Definition osg/Export:55
osgText::Text::GlyphQuads
Definition Text:216
osgText::Text::GlyphQuads::releaseGLObjects
void releaseGLObjects(osg::State *state=0) const
osgText::Text::GlyphQuads::getGlyphs
Glyphs & getGlyphs()
Definition Text:227
osgText::Text::GlyphQuads::getGlyphs
const Glyphs & getGlyphs() const
Definition Text:228
osgText::Text::GlyphQuads::setupPrimitives
void setupPrimitives(Text::BackdropType backdropType)
osgText::Text::GlyphQuads::GlyphQuads
GlyphQuads()
osgText::Text::GlyphQuads::resizeGLObjectBuffers
void resizeGLObjectBuffers(unsigned int maxSize)
osgText::Text::GlyphQuads::Glyphs
std::vector< Glyph * > Glyphs
Definition Text:217
osgText::Text::GlyphQuads::GlyphQuads
GlyphQuads(const GlyphQuads &gq)
osgText::Text::GlyphQuads::_glyphs
Glyphs _glyphs
Definition Text:219
osgText::Text::GlyphQuads::_primitives
osg::ref_ptr< osg::DrawElements > _primitives
Definition Text:220