Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Ogre::Font Class Reference

Class representing a font in the system. More...

#include <OgreFont.h>

Inheritance diagram for Ogre::Font:

Inheritance graph
[legend]
List of all members.

Public Methods

 Font (const String &name)
 Constructor.

virtual ~Font ()
void setType (FontType ftype)
 Sets the type of font.

FontType getType (void) const
 Gets the type of font.

void setSource (const String &source)
 Sets the source of the font.

const StringgetSource (void) const
 Gets the source this font (either an image or a truetype font).

void setTrueTypeSize (Real ttfSize)
 Sets the size of a truetype font (only required for FT_TRUETYPE).

void setTrueTypeResolution (uint ttfResolution)
 Gets the resolution (dpi) of the font used to generate the texture (only required for FT_TRUETYPE).

Real getTrueTypeSize (void) const
 Gets the point size of the font used to generate the texture.

uint getTrueTypeResolution (void) const
 Gets the resolution (dpi) of the font used to generate the texture.

std::pair< uint, uintStrBBox (const String &text, Real char_height, RenderWindow &window)
 Returns the size in pixels of a box that could contain the whole string.

virtual void load ()
 See Resource.

virtual void unload ()
 See Resource.

void getGlyphTexCoords (OgreChar id, Real &u1, Real &v1, Real &u2, Real &v2) const
 Returns the teture coordinates of the associated glyph.

void setGlyphTexCoords (OgreChar id, Real u1, Real v1, Real u2, Real v2)
 Sets the texture coordinates of a glyph.

Real getGlyphAspectRatio (OgreChar id) const
 Gets the aspect ratio (width / height) of this character.

void setGlyphAspectRatio (OgreChar id, Real ratio)
 Sets the aspect ratio (width / height) of this character.

const MaterialgetMaterial () const
 Gets the material generated for this font.

MaterialgetMaterial ()
 Gets the material generated for this font.

void setAntialiasColour (bool enabled)
 Sets whether or not the colour of this font is antialiased as it is generated from a true type font.

bool getAntialiasColour (void) const
virtual size_t getSize (void) const
 Retrieves info about the size of the resource.

virtual void touch (void)
 'Touches' the resource to indicate it has been used.

time_t getLastAccess (void) const
 Gets the last time the resource was 'touched'.

const StringgetName (void) const
 Gets resource name.

ResourceHandle getHandle (void) const
bool isLoaded (void) const
 Returns true if the Resource has been loaded, false otherwise.

virtual void destroy ()
 A method to make the resource delete itself.


Protected Methods

void createTextureFromFont (void)
 Internal method for loading from ttf.


Protected Attributes

FontType mType
 The type of font.

String mSource
 Source of the font (either an image name or a truetype font).

Real mTtfSize
 Size of the truetype font, in points.

uint mTtfResolution
 Resolution (dpi) of truetype font.

Real mTexCoords_u1 [OGRE_NUM_GLYPHS]
 Start u coords.

Real mTexCoords_u2 [OGRE_NUM_GLYPHS]
 End u coords.

Real mTexCoords_v1 [OGRE_NUM_GLYPHS]
 Start v coords.

Real mTexCoords_v2 [OGRE_NUM_GLYPHS]
 End v coords.

Real mAspectRatio [OGRE_NUM_GLYPHS]
 Aspect ratio between x and y (width / height).

MaterialmpMaterial
 The material which is generated for this font.

bool mAntialiasColour
 for TRUE_TYPE font only

String mName
ResourceHandle mHandle
bool mIsLoaded
time_t mLastAccess
size_t mSize

Detailed Description

Class representing a font in the system.

Remarks:
This class is simply a way of getting a font texture into the OGRE system and to easily retrieve the texture coordinates required to accurately render them. Fonts can either be loaded from precreated textures, or the texture can be generated using a truetype font. You can either create the texture manually in code, or you can use a .fontdef script to define it (probably more practical since you can reuse the definition more easily)

Definition at line 68 of file OgreFont.h.


Constructor & Destructor Documentation

Ogre::Font::Font const String   name
 

Constructor.

Parameters:
name  Mandatory name, must be unique.

Definition at line 52 of file OgreFont.cpp.

References Ogre::FT_TRUETYPE, mAntialiasColour, Ogre::Resource::mName, mpMaterial, mSource, mTtfResolution, mTtfSize, and mType.

Ogre::Font::~Font   [virtual]
 

Definition at line 66 of file OgreFont.cpp.


Member Function Documentation

void Ogre::Font::createTextureFromFont void    [protected]
 

Internal method for loading from ttf.

Definition at line 191 of file OgreFont.cpp.

References Ogre::Pass::createTextureUnitState(), Except, Ogre::FO_LINEAR, Ogre::FO_NONE, Ogre::Technique::getPass(), Ogre::DataChunk::getPtr(), Ogre::DataChunk::getSize(), Ogre::Material::getTechnique(), Ogre::Image::loadRawData(), Ogre::Resource::mName, mpMaterial, mSource, mTtfResolution, mTtfSize, Ogre::PF_A8R8G8B8, Ogre::Real, setGlyphTexCoords(), Ogre::TextureUnitState::setTextureFiltering(), Ogre::TEX_TYPE_2D, Ogre::uchar, and Ogre::uint.

Referenced by load().

virtual void Ogre::Resource::destroy void    [virtual, inherited]
 

A method to make the resource delete itself.

Note:
This exists because Resource objects could be created in other processes, and they need to be destroyed in the process that created them.

Definition at line 137 of file OgreResource.h.

bool Ogre::Font::getAntialiasColour void    const
 

Definition at line 248 of file OgreFont.h.

Real Ogre::Font::getGlyphAspectRatio OgreChar    id const
 

Gets the aspect ratio (width / height) of this character.

Definition at line 201 of file OgreFont.h.

References OGRE_GLYPH_INDEX, OgreChar, and Ogre::Real.

Referenced by Ogre::TextBoxGuiElement::processEvent(), Ogre::TTYGuiElement::setFontName(), StrBBox(), Ogre::TextAreaGuiElement::updateGeometry(), Ogre::TTYGuiElement::updateTextGeometry(), and Ogre::TTYGuiElement::updateWindowGeometry().

void Ogre::Font::getGlyphTexCoords OgreChar    id,
Real   u1,
Real   v1,
Real   u2,
Real   v2
const
 

Returns the teture coordinates of the associated glyph.

Remarks:
Parameter is a short to allow both ASCII and wide chars.
Parameters:
id  The character code
u1, u2, v1, v2  location to place the results

Definition at line 176 of file OgreFont.h.

References OGRE_GLYPH_INDEX, OgreChar, and Ogre::Real.

Referenced by StrBBox(), Ogre::TextAreaGuiElement::updateGeometry(), and Ogre::TTYGuiElement::updateWindowGeometry().

ResourceHandle Ogre::Resource::getHandle void    const [inherited]
 

Definition at line 120 of file OgreResource.h.

References Ogre::ResourceHandle.

Referenced by Ogre::Material::clone(), Ogre::BspLevel::loadQuake3Level(), and Ogre::ResourceManager::unload().

time_t Ogre::Resource::getLastAccess void    const [inherited]
 

Gets the last time the resource was 'touched'.

Definition at line 108 of file OgreResource.h.

Material* Ogre::Font::getMaterial void   
 

Gets the material generated for this font.

Remarks:
This will only be valid after the Font has been loaded.

Definition at line 228 of file OgreFont.h.

const Material* Ogre::Font::getMaterial void    const
 

Gets the material generated for this font.

Remarks:
This will only be valid after the Font has been loaded.

Definition at line 220 of file OgreFont.h.

Referenced by Ogre::TTYGuiElement::setFontName(), and Ogre::TextAreaGuiElement::setFontName().

const String& Ogre::Resource::getName void    const [inherited]
 

Gets resource name.

Reimplemented in Ogre::Material, and Ogre::Overlay.

Definition at line 115 of file OgreResource.h.

Referenced by Ogre::D3D9Texture::_loadCubeTex(), Ogre::Mesh::_notifySkeleton(), Ogre::ResourceManager::add(), Ogre::PopupMenuGuiElement::addListItem(), Ogre::ListGuiElement::addListItem(), Ogre::PopupMenuGuiElement::addMenuItem(), Ogre::MeshManager::createPrefabPlane(), Ogre::TTYGuiElement::getFontName(), Ogre::TextAreaGuiElement::getFontName(), Ogre::PopupMenuGuiElement::getListItemName(), Ogre::ListGuiElement::getListItemName(), Ogre::GpuProgramUsage::getProgramName(), Ogre::MeshSerializer::importMesh(), Ogre::GLTexture::load(), Ogre::TextureManager::loadImage(), Ogre::TextureManager::loadRawData(), Ogre::FontManager::logBadAttrib(), Ogre::MeshSerializerImpl_v1::readMaterial(), Ogre::MeshSerializerImpl::readMeshLodInfo(), Ogre::MeshSerializerImpl_v1::readMeshLodUsageGenerated(), Ogre::MeshSerializerImpl::readMeshLodUsageGenerated(), Ogre::MeshSerializerImpl::readMeshLodUsageManual(), Ogre::PopupMenuGuiElement::removeListItem(), Ogre::ListGuiElement::removeListItem(), Ogre::SceneManager::setSkyBox(), Ogre::SceneManager::setSkyDome(), and Ogre::ResourceManager::unload().

virtual size_t Ogre::Resource::getSize void    const [virtual, inherited]
 

Retrieves info about the size of the resource.

Definition at line 93 of file OgreResource.h.

Referenced by Ogre::ResourceManager::unload().

const String & Ogre::Font::getSource void    const
 

Gets the source this font (either an image or a truetype font).

Definition at line 96 of file OgreFont.cpp.

References mSource.

uint Ogre::Font::getTrueTypeResolution void    const
 

Gets the resolution (dpi) of the font used to generate the texture.

Remarks:
Only applicable for FT_TRUETYPE Font objects.

Definition at line 106 of file OgreFont.cpp.

References mTtfResolution, and Ogre::uint.

Real Ogre::Font::getTrueTypeSize void    const
 

Gets the point size of the font used to generate the texture.

Remarks:
Only applicable for FT_TRUETYPE Font objects. Note that the size of the font does not affect how big it is on the screen, just how large it is in the texture and thus how detailed it is.

Definition at line 101 of file OgreFont.cpp.

References mTtfSize, and Ogre::Real.

FontType Ogre::Font::getType void    const
 

Gets the type of font.

Definition at line 76 of file OgreFont.cpp.

References Ogre::FontType, and mType.

bool Ogre::Resource::isLoaded void    const [inherited]
 

Returns true if the Resource has been loaded, false otherwise.

Definition at line 127 of file OgreResource.h.

Referenced by Ogre::GpuProgramUsage::_load(), Ogre::SceneManager::deriveShadowCasterPass(), Ogre::SceneManager::deriveShadowReceiverPass(), Ogre::Technique::isLoaded(), Ogre::D3D9Texture::load(), Ogre::D3D9Texture::unload(), and Ogre::D3D9Texture::~D3D9Texture().

void Ogre::Font::load   [virtual]
 

See Resource.

Implements Ogre::Resource.

Definition at line 139 of file OgreFont.cpp.

References createTextureFromFont(), Ogre::Pass::createTextureUnitState(), Except, Ogre::FT_TRUETYPE, Ogre::Technique::getPass(), Ogre::Material::getTechnique(), Ogre::Pass::getTextureUnitState(), Ogre::Texture::hasAlpha(), Ogre::Resource::mIsLoaded, Ogre::Resource::mName, mpMaterial, mSource, mType, Ogre::SBT_ADD, Ogre::SBT_TRANSPARENT_ALPHA, Ogre::Material::setSceneBlending(), and Ogre::TextureUnitState::setTextureAddressingMode().

Referenced by Ogre::TTYGuiElement::setFontName(), and Ogre::TextAreaGuiElement::setFontName().

void Ogre::Font::setAntialiasColour bool    enabled
 

Sets whether or not the colour of this font is antialiased as it is generated from a true type font.

Remarks:
This is valid only for a FT_TRUETYPE font. If you are planning on using alpha blending to draw your font, then it is a good idea to set this to false (which is the default), otherwise the darkening of the font will combine with the fading out of the alpha around the edges and make your font look thinner than it should. However, if you intend to blend your font using a colour blending mode (add or modulate for example) then it's a good idea to set this to true, in order to soften your font edges.

Definition at line 243 of file OgreFont.h.

Referenced by Ogre::FontManager::parseAttribute().

void Ogre::Font::setGlyphAspectRatio OgreChar    id,
Real    ratio
 

Sets the aspect ratio (width / height) of this character.

Remarks:
You only need to call this if you're setting up a font loaded from a texture manually, and your aspect ratio is really freaky.

Definition at line 211 of file OgreFont.h.

References OGRE_GLYPH_INDEX, OgreChar, and Ogre::Real.

void Ogre::Font::setGlyphTexCoords OgreChar    id,
Real    u1,
Real    v1,
Real    u2,
Real    v2
 

Sets the texture coordinates of a glyph.

Remarks:
You only need to call this if you're setting up a font loaded from a texture manually.
Note:
Also sets the aspect ratio (width / height) of this character.

Definition at line 191 of file OgreFont.h.

References OGRE_GLYPH_INDEX, OgreChar, and Ogre::Real.

Referenced by createTextureFromFont(), and Ogre::FontManager::parseAttribute().

void Ogre::Font::setSource const String   source
 

Sets the source of the font.

Remarks:
If you have created a font of type FT_IMAGE, this method tells the Font which image to use as the source for the characters. So the parameter should be the name of an appropriate image file. Note that when using an image as a font source, you will also need to tell the font where each character is located using setGlyphTexCoords (for each character).

If you have created a font of type FT_TRUETYPE, this method tells the Font which .ttf file to use to generate the text. You will also need to call setTrueTypeSize and setTrueTypeResolution.

Parameters:
source  An image file or a truetype font, depending on the type of this font

Definition at line 81 of file OgreFont.cpp.

References mSource.

Referenced by Ogre::FontManager::parseAttribute().

void Ogre::Font::setTrueTypeResolution uint    ttfResolution
 

Gets the resolution (dpi) of the font used to generate the texture (only required for FT_TRUETYPE).

Parameters:
ttfResolution  The resolution in dpi

Definition at line 91 of file OgreFont.cpp.

References mTtfResolution, and Ogre::uint.

Referenced by Ogre::FontManager::parseAttribute().

void Ogre::Font::setTrueTypeSize Real    ttfSize
 

Sets the size of a truetype font (only required for FT_TRUETYPE).

Parameters:
ttfSize  The size of the font in points. Note that the size of the font does not affect how big it is on the screen, just how large it is in the texture and thus how detailed it is.

Definition at line 86 of file OgreFont.cpp.

References mTtfSize, and Ogre::Real.

Referenced by Ogre::FontManager::parseAttribute().

void Ogre::Font::setType FontType    ftype
 

Sets the type of font.

Must be set before loading.

Definition at line 71 of file OgreFont.cpp.

References Ogre::FontType, and mType.

Referenced by Ogre::FontManager::parseAttribute().

std::pair< uint, uint > Ogre::Font::StrBBox const String   text,
Real    char_height,
RenderWindow   window
 

Returns the size in pixels of a box that could contain the whole string.

Definition at line 111 of file OgreFont.cpp.

References getGlyphAspectRatio(), getGlyphTexCoords(), Ogre::RenderWindow::getMetrics(), Ogre::Real, and Ogre::uint.

virtual void Ogre::Resource::touch void    [virtual, inherited]
 

'Touches' the resource to indicate it has been used.

Reimplemented in Ogre::Material.

Definition at line 100 of file OgreResource.h.

Referenced by Ogre::Mesh::clone(), Ogre::MeshManager::createCurvedIllusionPlane(), Ogre::MeshManager::createCurvedPlane(), Ogre::MeshManager::createPlane(), and Ogre::ResourceManager::load().

void Ogre::Font::unload   [virtual]
 

See Resource.

Reimplemented from Ogre::Resource.

Definition at line 186 of file OgreFont.cpp.

References Ogre::Resource::mIsLoaded.


Member Data Documentation

bool Ogre::Font::mAntialiasColour [protected]
 

for TRUE_TYPE font only

Definition at line 99 of file OgreFont.h.

Referenced by Font().

Real Ogre::Font::mAspectRatio[OGRE_NUM_GLYPHS] [protected]
 

Aspect ratio between x and y (width / height).

Definition at line 93 of file OgreFont.h.

ResourceHandle Ogre::Resource::mHandle [protected, inherited]
 

Definition at line 57 of file OgreResource.h.

Referenced by Ogre::ResourceManager::add(), Ogre::Material::clone(), Ogre::Material::copyDetailsTo(), and Ogre::Material::operator=().

bool Ogre::Resource::mIsLoaded [protected, inherited]
 

Definition at line 58 of file OgreResource.h.

Referenced by Ogre::D3D9Texture::_initMembers(), Ogre::D3D9Texture::_loadCubeTex(), Ogre::D3D9Texture::_loadNormTex(), Ogre::D3D9Texture::_loadVolumeTex(), Ogre::Material::_notifyNeedsRecompile(), Ogre::Material::clone(), Ogre::D3DTexture::createSurface2D(), Ogre::D3DTexture::createSurface3D(), Ogre::D3D9Texture::D3D9Texture(), Ogre::D3DTexture::D3DTexture(), Ogre::DynLib::DynLib(), Ogre::Zip::load(), Ogre::SkeletonInstance::load(), Ogre::Skeleton::load(), Ogre::PatchMesh::load(), Ogre::Mesh::load(), Ogre::Material::load(), Ogre::HighLevelGpuProgram::load(), Ogre::GpuProgram::load(), Ogre::GLTexture::load(), load(), Ogre::DynLib::load(), Ogre::D3D9Texture::load(), Ogre::D3D9GpuProgram::load(), Ogre::D3DTexture::load(), Ogre::BspLevel::load(), Ogre::D3D9Texture::loadImage(), Ogre::D3DTexture::loadImage(), Ogre::D3DTexture::loadImage3D(), Ogre::GLTexture::loadImages(), Ogre::Material::Material(), Ogre::Material::operator=(), Ogre::Skeleton::unload(), Ogre::Mesh::unload(), Ogre::Material::unload(), Ogre::HighLevelGpuProgram::unload(), Ogre::GLTexture::unload(), unload(), Ogre::DynLib::unload(), Ogre::D3D9Texture::unload(), Ogre::D3DTexture::unload(), and Ogre::BspLevel::~BspLevel().

time_t Ogre::Resource::mLastAccess [protected, inherited]
 

Definition at line 59 of file OgreResource.h.

Referenced by Ogre::Material::operator=().

String Ogre::Resource::mName [protected, inherited]
 

Definition at line 56 of file OgreResource.h.

Referenced by Ogre::Skeleton::_dumpContents(), Ogre::Mesh::_rationaliseBoneAssignments(), Ogre::BspLevel::BspLevel(), Ogre::Mesh::buildEdgeList(), Ogre::Mesh::buildTangentVectors(), Ogre::Material::clone(), Ogre::Material::compile(), Ogre::Material::copyDetailsTo(), Ogre::Quake3Shader::createAsMaterial(), Ogre::D3D9HLSLProgram::createLowLevelImpl(), Ogre::CgProgram::createLowLevelImpl(), createTextureFromFont(), Ogre::D3D9Texture::D3D9Texture(), Ogre::D3DTexture::D3DTexture(), Ogre::DynLib::DynLib(), Font(), Ogre::Mesh::generateLodLevels(), Ogre::Material::getBestTechnique(), Ogre::Overlay::getName(), Ogre::Material::getName(), Ogre::GLTexture::GLTexture(), Ogre::GpuProgram::GpuProgram(), Ogre::Zip::load(), Ogre::Skeleton::load(), Ogre::Mesh::load(), Ogre::GLTexture::load(), load(), Ogre::DynLib::load(), Ogre::D3DTexture::load(), Ogre::BspLevel::load(), Ogre::D3D9GpuFragmentProgram::loadFromMicrocode(), Ogre::D3D9GpuVertexProgram::loadFromMicrocode(), Ogre::GLArbGpuProgram::loadFromSource(), Ogre::D3D9HLSLProgram::loadFromSource(), Ogre::D3D9GpuProgram::loadFromSource(), Ogre::CgProgram::loadFromSource(), Ogre::GLTexture::loadImages(), Ogre::Material::Material(), Ogre::Mesh::Mesh(), Ogre::Material::operator=(), Ogre::Overlay::Overlay(), Ogre::Quake3Shader::Quake3Shader(), Ogre::CgProgram::selectProfile(), Ogre::Mesh::setSkeletonName(), Ogre::Skeleton::Skeleton(), Ogre::StringResource::StringResource(), Ogre::Zip::unload(), Ogre::DynLib::unload(), Ogre::CgProgram::unloadImpl(), and Ogre::Zip::Zip().

Material* Ogre::Font::mpMaterial [protected]
 

The material which is generated for this font.

Definition at line 96 of file OgreFont.h.

Referenced by createTextureFromFont(), Font(), and load().

size_t Ogre::Resource::mSize [protected, inherited]
 

Definition at line 60 of file OgreResource.h.

Referenced by Ogre::D3D9Texture::_setFinalAttributes(), Ogre::D3DTexture::loadImage(), Ogre::D3DTexture::loadImage3D(), Ogre::GLTexture::loadImages(), and Ogre::Material::operator=().

String Ogre::Font::mSource [protected]
 

Source of the font (either an image name or a truetype font).

Definition at line 75 of file OgreFont.h.

Referenced by createTextureFromFont(), Font(), getSource(), load(), and setSource().

Real Ogre::Font::mTexCoords_u1[OGRE_NUM_GLYPHS] [protected]
 

Start u coords.

Definition at line 84 of file OgreFont.h.

Real Ogre::Font::mTexCoords_u2[OGRE_NUM_GLYPHS] [protected]
 

End u coords.

Definition at line 86 of file OgreFont.h.

Real Ogre::Font::mTexCoords_v1[OGRE_NUM_GLYPHS] [protected]
 

Start v coords.

Definition at line 88 of file OgreFont.h.

Real Ogre::Font::mTexCoords_v2[OGRE_NUM_GLYPHS] [protected]
 

End v coords.

Definition at line 90 of file OgreFont.h.

uint Ogre::Font::mTtfResolution [protected]
 

Resolution (dpi) of truetype font.

Definition at line 80 of file OgreFont.h.

Referenced by createTextureFromFont(), Font(), getTrueTypeResolution(), and setTrueTypeResolution().

Real Ogre::Font::mTtfSize [protected]
 

Size of the truetype font, in points.

Definition at line 78 of file OgreFont.h.

Referenced by createTextureFromFont(), Font(), getTrueTypeSize(), and setTrueTypeSize().

FontType Ogre::Font::mType [protected]
 

The type of font.

Definition at line 72 of file OgreFont.h.

Referenced by Font(), getType(), load(), and setType().


The documentation for this class was generated from the following files:

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:26:09 2004