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

gl::ttf Class Reference

True type font renderer. More...

#include <ttf.h>

Collaboration diagram for gl::ttf:

Collaboration graph
[legend]
List of all members.

Public Types

typedef std::hash_map< char,
glyph *, std::hash< char >,
eqchar
glyph_hash
 Hash of glyphs.


Public Methods

 ttf (void)
 Constructor.

 ttf (const ttf &cpy)
 Copy Constructor.

 ~ttf (void)
 Destructor.

ttf & operator= (const ttf &cpy)
 Assignment operator.

void render_string (real_t &x, real_t &y, real_t size, const std::string &text) const
 Renders a string of text to the screen. More...

std::string get_name (void) const
 Returns the name (filename) of the font.

 operator bool (void) const
 Returns true if the font is not in an error state.

texture get_texture (void) const
 Returns a gl::texture to the texture that stores this font's glyphs.


Static Public Methods

ttf * load (const std::string &filename, unsigned int pt_size)
 Loads a font from a file.


Detailed Description

True type font renderer.

This object enables the rendering of high quality true type fonts to an OpenGL context. Using this object is as simple as:

 //load the font (32 is the request height of the font in pixels)
 gl::ttf *font = gl::ttf::load( "myfont.ttf", 32 );
 if( !font) {
     std::cerr << "could not load font" << std::endl;
 }

 //render a string to the screen
 int x = 0, y = 0;
 video.render( x, y, font, 32, "I like chessee." );
 //x and y now contain the location of the last rendered pixel

Note that the easiest way to render strings is to use Uber's virtual coordinate system with video_base::render_string.

Also note that if you plan on making multiple calls to video_base::render_string it may be benificial to call video_base::enable_2d to avoid unneccessay 2d/3d state flips.

See demos/fontviewer for a demo using this object.

Definition at line 56 of file ttf.h.


Member Function Documentation

void gl::ttf::render_string real_t   x,
real_t   y,
real_t    size,
const std::string &    text
const
 

Renders a string of text to the screen.

Renders a string of text to the screen. All values are in frame buffer coordinates NOT virtual coordinates. If you want to use Uber's virtual coordinate system, use video_base::render_string. (0,0) is located at the lower left hand corner of the screen.

Parameters:
x  x location of pixel to render to in frame buffer. Updated to be the x coordinate of the upper right hand pixel of the last glyph rendered.
y  y location of pixel to render to in frame buffer. Updated to be the y coordinate of the upper right hand pixel of the last glyph rendered.
height  Height of the string.
text  String to be rendered.

Definition at line 52 of file ttf.cpp.

References real_t.

Referenced by video_base::render_shadowed_string, and video_base::render_string.


Generated on Tue Feb 11 18:49:48 2003 for uber by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002