Contents Functions Classes Topics User Forum CVS

G3D::GFont Class Reference

#include <GFont.h>

Inherits G3D::ReferenceCountedObject.

List of all members.

Public Types

enum  XAlign { XALIGN_RIGHT, XALIGN_LEFT, XALIGN_CENTER }
enum  YAlign { YALIGN_TOP, YALIGN_BASELINE, YALIGN_CENTER, YALIGN_BOTTOM }
enum  Spacing { PROPORTIONAL_SPACING, FIXED_SPACING }

Public Member Functions

Vector2 texelSize () const
Vector2 draw2D (RenderDevice *renderDevice, const std::string &s, const Vector2 &pos2D, double size=12, const Color4 &color=Color3::black(), const Color4 &outline=Color4::clear(), XAlign xalign=XALIGN_LEFT, YAlign yalign=YALIGN_TOP, Spacing spacing=PROPORTIONAL_SPACING) const
Vector2 G3D_DEPRECATED draw2D (const std::string &s, const Vector2 &pos2D, double size=12, const Color4 &color=Color3::black(), const Color4 &outline=Color4::clear(), XAlign xalign=XALIGN_LEFT, YAlign yalign=YALIGN_TOP, Spacing spacing=PROPORTIONAL_SPACING) const
Vector2 draw3D (RenderDevice *renderDevice, const std::string &s, const CoordinateFrame &pos3D, double size=.1, const Color4 &color=Color3::black(), const Color4 &outline=Color4::clear(), XAlign xalign=XALIGN_LEFT, YAlign yalign=YALIGN_TOP, Spacing spacing=PROPORTIONAL_SPACING) const
Vector2 G3D_DEPRECATED draw3D (const std::string &s, const CoordinateFrame &pos3D, double size=.1, const Color4 &color=Color3::black(), const Color4 &outline=Color4::clear(), XAlign xalign=XALIGN_LEFT, YAlign yalign=YALIGN_TOP, Spacing spacing=PROPORTIONAL_SPACING) const
Vector2 get2DStringBounds (const std::string &s, double size=12, Spacing spacing=PROPORTIONAL_SPACING) const
void ReferenceCountedObject_zeroWeakPointers ()

Static Public Member Functions

static GFontRef G3D_DEPRECATED fromFile (class RenderDevice *renderDevice, const std::string &filename)
static GFontRef fromFile (const std::string &filename)
static GFontRef fromMemory (const std::string &name, const uint8 *bytes, const int size)
static void convertRAWINItoPWF (const std::string &infileBase, std::string outfile="")

Public Attributes

AtomicInt32 ReferenceCountedObject_refCount
_WeakPtrLinkedListReferenceCountedObject_weakPointer


Detailed Description

Font class for use with RenderDevice. Renders variable size and color fonts from high-resolution bitmaps.

Font rendering is (inherently) slow-- you can achieve better performance for static text by creating bitmap textures with whole words and sentences on them.

The following fonts are provided with G3D in the data/font directory. See the copyright.txt file in that directory for information about the source of these files and rules for distribution.

font.png


Member Enumeration Documentation

enum G3D::GFont::Spacing
 

Constant for draw2D. Proportional width (default) spaces characters based on their size. Fixed spacing gives uniform spacing regardless of character width.

Enumerator:
PROPORTIONAL_SPACING 
FIXED_SPACING 

enum G3D::GFont::XAlign
 

Constant for draw2D. Specifies the horizontal alignment of an entire string relative to the supplied x,y position

Enumerator:
XALIGN_RIGHT 
XALIGN_LEFT 
XALIGN_CENTER 

enum G3D::GFont::YAlign
 

Constant for draw2D. Specifies the vertical alignment of the characters relative to the supplied x,y position.

Enumerator:
YALIGN_TOP 
YALIGN_BASELINE 
YALIGN_CENTER 
YALIGN_BOTTOM 


Member Function Documentation

static void G3D::GFont::convertRAWINItoPWF const std::string &  infileBase,
std::string  outfile = ""
[static]
 

Converts an 8-bit RAW font texture and INI file as produced by the Bitmap Font Builder program to a graphics3d PWF font. inFile should have no extension-- .raw and .ini will be appended to it. outfile should end with ".FNT" or be "" for the default.

The Bitmap Font Builder program can be downloaded from http://www.lmnopc.com/bitmapfontbuilder/

Use the full ASCII character set; the conversion will strip infrequently used characters automatically. Write out RAW files with characters CENTER aligned and right side up using this program. Then, also write out an INI file; this contains the width of each character in the font. Example:

	  GFont::convertRAWINItoPWF("c:/tmp/g3dfont/news",
	                            "d:/graphics3d/book/cpp/data/font/news.fnt"); 
      

Parameters:
infileBase The name of the raw/ini files
outfile Defaults to infileBase + ".fnt"

Vector2 G3D_DEPRECATED G3D::GFont::draw2D const std::string &  s,
const Vector2 pos2D,
double  size = 12,
const Color4 color = Color3::black(),
const Color4 outline = Color4::clear(),
XAlign  xalign = XALIGN_LEFT,
YAlign  yalign = YALIGN_TOP,
Spacing  spacing = PROPORTIONAL_SPACING
const [inline]
 

Deprecated:
Use the version that accepts a RenderDevice as the 1st argument.

Vector2 G3D::GFont::draw2D RenderDevice renderDevice,
const std::string &  s,
const Vector2 pos2D,
double  size = 12,
const Color4 color = Color3::black(),
const Color4 outline = Color4::clear(),
XAlign  xalign = XALIGN_LEFT,
YAlign  yalign = YALIGN_TOP,
Spacing  spacing = PROPORTIONAL_SPACING
const
 

Draws a proportional width font string. Assumes device->push2D() has been called. Leaves all rendering state as it was, except for the texture coordinate on unit 0.

Parameters:
size The distance between successive lines of text. Specify texelSize().y / 1.5 to get 1:1 texel to pixel
outline If this color has a non-zero alpha, a 1 pixel border of this color is drawn about the text.
spacing Fixed width fonts are spaced based on the width of the 'M' character.
Returns:
Returns the x and y bounds (ala get2DStringBounds) of the printed string.
You can draw rotated text by setting the RenderDevice object to world matrix manually. The following example renders the word "ANGLE" on a 45-degree angle at (100, 100).
    app->renderDevice->push2D();
        CoordinateFrame cframe(
            Matrix3::fromAxisAngle(Vector3::unitZ(), toRadians(45)),
            Vector3(100, 100, 0));
        app->renderDevice->setObjectToWorldMatrix(cframe);
        app->debugFont->draw2D("ANGLE", Vector2(0, 0), 20);
    app->renderDevice->pop2D();
     

Vector2 G3D_DEPRECATED G3D::GFont::draw3D const std::string &  s,
const CoordinateFrame pos3D,
double  size = .1,
const Color4 color = Color3::black(),
const Color4 outline = Color4::clear(),
XAlign  xalign = XALIGN_LEFT,
YAlign  yalign = YALIGN_TOP,
Spacing  spacing = PROPORTIONAL_SPACING
const [inline]
 

Deprecated:
Use the version that accepts a RenderDevice as the 1st argument.

Vector2 G3D::GFont::draw3D RenderDevice renderDevice,
const std::string &  s,
const CoordinateFrame pos3D,
double  size = .1,
const Color4 color = Color3::black(),
const Color4 outline = Color4::clear(),
XAlign  xalign = XALIGN_LEFT,
YAlign  yalign = YALIGN_TOP,
Spacing  spacing = PROPORTIONAL_SPACING
const
 

Text is visible from behind. The text is oriented so that it reads "forward" when the pos3D z-axis points towards the viewer.

Note that text, like all transparent objects, should be rendered in back to front sorted order to achieve proper alpha blending.

Parameters:
size In meters.

static GFontRef G3D::GFont::fromFile const std::string &  filename  )  [static]
 

The filename must be a FNT (proportional width font) file.

If a font file is not found, an assertion will fail, an exception will be thrown, and texelSize() will return (0, 0).

Several fonts in this format at varying resolutions are available in the data/font directory. The large fonts require 500k of memory when loaded and look good when rendering characters up to about 64 pixels high. The small fonts require 130k and look good up to about 32 pixels.

See GFont::convertTGAtoPWF for creating new fonts in the FNT format:

This file is compressed by BinaryOutput::compress(). The contents after decompression have the following format (little endian):

           int32                       Version number (must be 1)
           128 * int16                 Character widths, in texels
           uint16                      Baseline from top of box, in texels
           uint16                      Texture width (texture height is always 1/2 texture width)
           (pow(width, 2) / 2) * int8  Texture data
          
The width of a character's bounding box is always width / 16. The height is always width / 8.

static GFontRef G3D_DEPRECATED G3D::GFont::fromFile class RenderDevice renderDevice,
const std::string &  filename
[static]
 

Deprecated:

static GFontRef G3D::GFont::fromMemory const std::string &  name,
const uint8 bytes,
const int  size
[static]
 

see GFont::fromFile

Vector2 G3D::GFont::get2DStringBounds const std::string &  s,
double  size = 12,
Spacing  spacing = PROPORTIONAL_SPACING
const
 

Useful for drawing centered text and boxes around text.

void G3D::ReferenceCountedObject::ReferenceCountedObject_zeroWeakPointers  )  [inline, inherited]
 

Automatically called immediately before the object is deleted. This is not called from the destructor because it needs to be invoked before the subclass destructor.

Vector2 G3D::GFont::texelSize  )  const
 

Returns the natural character width and height of this font.


Member Data Documentation

AtomicInt32 G3D::ReferenceCountedObject::ReferenceCountedObject_refCount [inherited]
 

The long name is to keep this from accidentally conflicting with a subclass's variable name. Do not use or explicitly manipulate this value--its type may change in the future and is not part of the supported API.

_WeakPtrLinkedList* G3D::ReferenceCountedObject::ReferenceCountedObject_weakPointer [inherited]
 

Linked list of all weak pointers that reference this (some may be on the stack!). Do not use or explicitly manipulate this value.


The documentation for this class was generated from the following file:
Generated on Mon Jul 17 11:50:47 2006 for G3D by doxygen 1.4.5
Hosted by SourceForge.net Logo