Documentation ¶
Overview ¶
The gltext package offers a set of text rendering utilities for OpenGL programs. It deals with TrueType and Bitmap (raster) fonts.
Text can be rendered in predefined directions (Left-to-right, right-to-left and top-to-bottom). This allows for correct display of text for various languages.
This package supports the full set of unicode characters, provided the loaded font does as well.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Pow2 ¶
Pow2 returns the first power-of-two value >= to n. This can be used to create suitable texture dimensions.
func Pow2Image ¶
Pow2Image returns the given image, scaled to the smallest power-of-two dimensions larger or equal to the input dimensions. It preserves the image format and contents.
This is useful if an image is to be used as an OpenGL texture. These often require image data to have power-of-two dimensions.
Types ¶
type Charset ¶
type Charset []Glyph
A Charset represents a set of glyph descriptors for a font. Each glyph descriptor holds glyph metrics which are used to properly align the given glyph in the resulting rendered string.
func (Charset) Scale ¶
Scale scales all glyphs by the given factor and repositions them appropriately. A scale of 1 retains the original size. A scale of 2 doubles the size of each glyph, etc.
This is useful when the accompanying sprite sheet is scaled by the same factor. In this case, we want the glyph data to match up with the new image.
type Direction ¶
type Direction uint8
Direction represents the direction in which strings should be rendered.
type Font ¶
type Font struct {
// contains filtered or unexported fields
}
A Font allows rendering of text to an OpenGL context.
func LoadTruetype ¶
func LoadTruetype(r io.Reader, uploader TextureUploader, scale int32, low, high rune, dir Direction) (*Font, error)
LoadTruetype loads a truetype font from the given stream and applies the given font scale in points.
The low and high values determine the lower and upper rune limits we should load for this font. For standard ASCII this would be: 32, 127.
The dir value determines the orientation of the text we render with this font. This should be any of the predefined Direction constants.
func (*Font) GlyphBounds ¶
GlyphBounds returns the largest width and height for any of the glyphs in the font. This constitutes the largest possible bounding box a single glyph will have.
type FontConfig ¶
type FontConfig struct { // The direction determines the orientation of rendered strings and should // hold any of the pre-defined Direction constants. Dir Direction `json:"direction"` // Lower rune boundary Low rune `json:"rune_low"` // Upper rune boundary. High rune `json:"rune_high"` // Glyphs holds a set of glyph descriptors, defining the location, // size and advance of each glyph in the sprite sheet. Glyphs Charset `json:"glyphs"` }
FontConfig describes raster font metadata.
It can be loaded from, or saved to a JSON encoded file, which should come with any bitmap font image.
type Glyph ¶
type Glyph struct { X int `json:"x"` // The x location of the glyph on a sprite sheet. Y int `json:"y"` // The y location of the glyph on a sprite sheet. Width int `json:"width"` // The width of the glyph on a sprite sheet. Height int `json:"height"` // The height of the glyph on a sprite sheet. // Advance determines the distance to the next glyph. // This is used to properly align non-monospaced fonts. Advance int `json:"advance"` // contains filtered or unexported fields }
A Glyph describes metrics for a single font glyph. These indicate which area of a given image contains the glyph data and how the glyph should be spaced in a rendered string.