Io Reference







Graphics   /   Font   /   Font





The Font object can be used to load and render TypeTrype fonts. Example use;
	
// within a GLUT display callback...

timesFont = Font clone open(\"times.ttf\")
if (timesFont error, write(\"Error loading font: \", timesFont error, \"\n\"); return)
timesFont setPointSize(16)
glColor(0,0,0,1)
timesFont draw(\"This is a test.\")
Rendering fonts using OpenGL textures

Smaller fonts (those having a point size around 30 or smaller, depending on the font) will automatically be cached in and rendered from a texture. This technique is very fast and should support rendering speeds as fast (or faster than) those of typical desktop font rendering systems. Larger font sizes(due to texture memory constraints) will be rendered to a pixelmap when displayed. Thanks to Mike Austin for implementing the font texturing system.

 
 
 



drawString(aString, optionalStartIndex, optionalEndIndex)

Draws aString using the optional start and end indexes, if supplied. Returns self.

Note; Fonts are drawn as RGBA pixel maps. These blending options are recommended:

	
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
error

Returns the current error string or nil if there is no error.
isTextured

Returns true if the font is being cached in and rendered from a texture, false otherwise.
open(optionalPath)

Opens the font. Sets path using optionalPath if supplied. Returns self.
path

Returns the Font path.
pixelHeight

Returns the height of the font measured in pixels.
pixelSize

Returns the font's pixelSize.
setPath(aString)

Sets the Font path. Returns self.
setPixelSize(aNumber)

Sets the size of the font in pixels. Returns self.
stringIndexAtWidth(aString, startIndex, width)

Returns the max index of the character in String (starting at startIndex) that fits within width.
widthOfCharacter(aNumber)

Returns the width of the character specified by aNumber in the receiver's font.
widthOfString(aString)

Returns a Number with the width that aString would render to with the receiver's current settings.