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 NewProgram(vertexShaderSource, fragmentShaderSource string) (uint32, 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 BoundingBox
- type CharacterSide
- type Charset
- type Direction
- type Font
- type FontConfig
- type FontLike
- type Glyph
- type Point
- type RuneRange
- type RuneRanges
- type Text
- func (t *Text) AddScale(s float32) bool
- func (t *Text) BeginFadeOut()
- func (t *Text) CharPosition(index int) float64
- func (t *Text) ClickedCharacter(xPos, offset float64) (index int, side CharacterSide)
- func (t *Text) Draw()
- func (t *Text) GetBoundingBox() (X1, X2 Point)
- func (t *Text) GetLength() int
- func (t *Text) HasRune(r rune) bool
- func (t *Text) Height() float32
- func (t *Text) Hide()
- func (t *Text) PrintCharSpacing()
- func (t *Text) Release()
- func (t *Text) SetColor(color mgl32.Vec3)
- func (t *Text) SetPosition(v mgl32.Vec2)
- func (t *Text) SetScale(s float32) bool
- func (t *Text) SetString(fs string, argv ...interface{})
- func (t *Text) Show()
- func (t *Text) Width() float32
Constants ¶
This section is empty.
Variables ¶
var IsDebug = false
Functions ¶
func DebugPrefix ¶
func DebugPrefix() string
func NewProgram ¶
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 BoundingBox ¶
type BoundingBox struct { // X1, X2: the lower left and upper right points of a box that bounds the text X1 Point X2 Point // contains filtered or unexported fields }
func (*BoundingBox) Draw ¶
func (b *BoundingBox) Draw()
func (*BoundingBox) Release ¶
func (b *BoundingBox) Release()
type CharacterSide ¶
type CharacterSide int
CharacterSide shows which side of a character is clicked
const ( CSLeft CharacterSide = iota CSRight CSUnknown )
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 { Config *FontConfig // Character set for this font. OrthographicMatrix mgl32.Mat4 WindowWidth float32 WindowHeight float32 // contains filtered or unexported fields }
func (*Font) GetTextureHeight ¶
func (*Font) GetTextureWidth ¶
func (*Font) ResizeWindow ¶
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 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, *image.NRGBA, error)
func NewFromConfig ¶
func NewFromConfig(rootPath, name string) (*FontConfig, *image.NRGBA, error)
Load reads font configuration data from the given JSON encoded stream.
func NewTruetypeFontConfig ¶
func NewTruetypeFontConfig(r io.Reader, scale fixed.Int26_6, runeRanges RuneRanges, runesPerRow, adjustHeight fixed.Int26_6) (*FontConfig, *image.NRGBA, 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.
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
type Text ¶
type Text struct { Font *Font // scaling the text Scale float32 ScaleMin float32 ScaleMax float32 // Fadeout reduces alpha FadeOutBegun bool FadeOutFrameCount float32 // number of frames since drawing began FadeOutPerFrame float32 // smaller value takes more time // bounding box of text BoundingBox *BoundingBox // determines how many prefix characters are drawn on screen RuneCount int // no longer than this string MaxRuneCount int // lower left X1 Point // upper right X2 Point // Screen position away from center Position mgl32.Vec2 String string CharSpacing []float32 // contains filtered or unexported fields }
Text is not designed to be accessed concurrently
func NewText ¶
NewText creates a new text object with scaling boundaries the rest state of the text when not being interacted with is scaleMin. most likely one wants to use 1.0.
func (*Text) BeginFadeOut ¶
func (t *Text) BeginFadeOut()
func (*Text) CharPosition ¶
func (*Text) ClickedCharacter ¶
func (t *Text) ClickedCharacter(xPos, offset float64) (index int, side CharacterSide)
ClickedCharacter should only be called after a bounding box hit is confirmed because it does not check y-axis values at all. Returns the index and side of the char clicked.
func (*Text) GetBoundingBox ¶
func (*Text) PrintCharSpacing ¶
func (t *Text) PrintCharSpacing()
PrintCharSpacing is used for debugging
func (*Text) SetPosition ¶
SetPosition prepares variables passed to the shader as well as values used for bounding box calculations when clicking or hovering above text