glsymbol

package module
v0.0.0-...-89782ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 9 Imported by: 2

README

glsymbol

draw symbol in opengl (based on https://github.com/go-gl/gltext)

Documentation

Overview

The glsymbol 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.

This packages uses freetype-go (code.google.com/p/freetype-go) which is licensed under GPLv2 e FTL licenses. You can choose which one is a better fit for your use case but FTL requires you to give some form of credit to Freetype.org

You can read the GPLv2 (https://code.google.com/p/freetype-go/source/browse/licenses/gpl.txt) and FTL (https://code.google.com/p/freetype-go/source/browse/licenses/ftl.txt) licenses for more information about the requirements.

Index

Constants

This section is empty.

Variables

View Source
var DefaultEmbeddedFont string

Functions

func Pow2

func Pow2(x uint32) uint32

Pow2 returns the first power-of-two value >= to n. This can be used to create suitable texture 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.

type Font

type Font struct {
	Config         *FontConfig // Character set for this font.
	MaxGlyphWidth  int32       // Largest glyph width.
	MaxGlyphHeight int32       // Largest glyph height.
}

A Font allows rendering of text to an OpenGL context.

func DefaultFont

func DefaultFont() (_ *Font, err error)

DefaultFont return default font

func LoadTruetype

func LoadTruetype(r io.Reader, scale int32, low, high rune) (_ *Font, err 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

func (f *Font) GlyphBounds() (int32, int32)

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.

func (*Font) Printf

func (f *Font) Printf(x, y float32, str string) error

Printf draws the given string at the specified coordinates. It expects the string to be a single line. Line breaks are not handled as line breaks and are rendered as glyphs.

In order to render multi-line text, it is up to the caller to split the text up into individual lines of adequate length and then call this method for each line seperately.

func (*Font) Release

func (f *Font) Release()

Release releases font resources. A font can no longer be used for rendering after this call completes.

type FontConfig

type FontConfig struct {
	// Lower rune boundary
	Low rune

	// Upper rune boundary.
	High rune

	// Glyphs holds a set of glyph descriptors, defining the location,
	// size and advance of each glyph in the sprite sheet.
	Glyphs Charset
}

FontConfig describes raster font metadata.

which should come with any bitmap font image.

type Glyph

type Glyph struct {
	X      int32 // The x location of the glyph on a sprite sheet.
	Y      int32 // The y location of the glyph on a sprite sheet.
	Width  int32 // The width of the glyph on a sprite sheet.
	Height int32 // 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 int32

	// Bitmap data of glyph
	BitmapData []uint8
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL