Documentation ¶
Index ¶
- Variables
- func DebugPrefix() string
- func IsPow2(x uint32) bool
- func LoadFontImage(rootPath, name string) (*image.NRGBA, error)
- func LoadImage(path string) (*image.NRGBA, error)
- func Pow2(x uint32) uint32
- func Pow2Image(src image.Image) image.Image
- func PrintVBO(vbo []float32, w, h float32)
- func SaveImage(rootPath, name string, img *image.NRGBA) error
- func TextDebug(message string)
- type Charset
- type Direction
- type FontConfig
- type FontLike
- type Glyph
- type Point
- type RuneRange
- type RuneRanges
Constants ¶
This section is empty.
Variables ¶
var IsDebug = false
Functions ¶
func DebugPrefix ¶
func DebugPrefix() string
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.
func PrintVBO ¶
PrintVBO prints the individual index locations as well as the texture locations
(0,0) (x1,y1): This shows the layout of the runes. There relative locations to one another can be seen here.
- If called just after makeBufferData, the left-most x value will start at 0.
- If called after centerTheData, all indices will have been shifted so that the entire text value is centered around the screen's origin of (0,0).
(U,V) (u1,v1) -> (x,y): The (x,y) values refer to pixel locations within the texture
- Open the texture in an image editor and, using the upper left hand corner as (0,0) move to the location (x,y). This is where opengl will pinpoint your rune within the image.
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 FontConfig ¶
type FontConfig struct { // The range of glyphs covered by this fontconfig // An array of Low, High values allowing the user to select disjoint subsets of the ttf RuneRanges RuneRanges // Glyphs holds a set of glyph descriptors, defining the location, // size and advance of each glyph in the sprite sheet. Glyphs Charset Image *image.NRGBA `json:"-"` Name string }
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.
func LoadTruetypeFontConfig ¶
func LoadTruetypeFontConfig(rootPath, name string) (*FontConfig, error)
func NewTruetypeFontConfig ¶
func NewTruetypeFontConfig(r io.Reader, scale fixed.Int26_6, runeRanges RuneRanges, runesPerRow, adjustHeight fixed.Int26_6) (*FontConfig, 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.
func (*FontConfig) Load ¶
func (fc *FontConfig) Load(rootPath string) (err error)
Load reads font configuration data from the given JSON encoded stream.
func (*FontConfig) Save ¶
func (fc *FontConfig) Save(rootPath, name string) error
Save writes font configuration data to the given stream as JSON data.
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"` }
func (*Glyph) GetTexturePositions ¶
type Point ¶
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.
type RuneRange ¶
type RuneRange struct {
Low, High rune
}
RuneRanges specify the rune ranges for ordered disjoint subsets of the ttf EG 32 - 127, 5000 - 6000 will created a more compact bitmap that holds the specified ranges of runes.
type RuneRanges ¶
type RuneRanges []RuneRange
func (RuneRanges) GetGlyphIndex ¶
func (rr RuneRanges) GetGlyphIndex(char rune) rune
GetGlyphIndex returns the location of the glyph data within the compressed rune ranges covered by the font EG if runes 0-25, 100-110 are supported by the font then the actual location of 100 will be in position 26 in the png image
func (RuneRanges) Len ¶
func (rr RuneRanges) Len() int
func (RuneRanges) Less ¶
func (rr RuneRanges) Less(i, j int) bool
func (RuneRanges) Swap ¶
func (rr RuneRanges) Swap(i, j int)
func (RuneRanges) Validate ¶
func (rr RuneRanges) Validate() bool