bitmapfont

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 12 Imported by: 0

README

bitmapfont rendering for OpenGL

example

Bitmpafont demo

format

usage

font, _ := bitmapfont.NewOpenGLFont("test_ubuntu.fnt", "test_ubuntu.png")
defer font.Delete()

multitext := `Bitmapfont
easy OpenGL font rendering
for Go`
txt := bitmapfont.NewText(multitext, 10, 10, 300, 100, font)

txt.Render()

TODO

  • multi-byte chars
  • optimize amount lookup

(c) 2016, http://ernestmicklei.com. MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Char

type Char struct {
	Id       uint8   // The character id.
	X        float32 // The left position of the character image in the texture.
	Y        float32 // The top position of the character image in the texture.
	Width    float32 // The width of the character image in the texture.
	Height   float32 // The height of the character image in the texture.
	Xoffset  float32 // How much the current position should be offset when copying the image from the texture to the screen.
	Yoffset  float32 // How much the current position should be offset when copying the image from the texture to the screen.
	Xadvance float32 // How much the current position should be advanced after drawing the character.
	Page     int     //	The texture page where the character image is found.
	Channel  int     //	The texture channel where the character image is found (1 = blue, 2 = green, 4 = red, 8 = alpha, 15 = all channels).
	Letter   string  // The letter is represents
}

This tag describes on character in the font. There is one for each included character in the font.

type Common

type Common struct {
	LineHeight float32 // This is the distance in pixels between each line of text.
	Base       int     // The number of pixels from the absolute top of the line to the base of the characters.
	ScaleW     float32 // The width of the texture, normally used to scale the x pos of the character image.
	ScaleH     float32 // The height of the texture, normally used to scale the y pos of the character image.
	Pages      int     // The number of texture pages included in the font.
	Packed     int     // Set to 1 if the monochrome characters have been packed into each of the texture channels. In this case alphaChnl describes what is stored in each channel.
	AlphaChnl  int     // Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one.
	RedChnl    int     // Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one.
	GreenChnl  int     // Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one.
	BlueChnl   int     // Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one.
}

This tag holds information common to all characters.

type Font

type Font struct {
	Common Common
	// contains filtered or unexported fields
}

func NewFont

func NewFont() *Font

func (*Font) AmountBetween

func (f *Font) AmountBetween(left, right uint8) float32

func (*Font) Base

func (f *Font) Base() float32

func (*Font) CharAt

func (f *Font) CharAt(c uint8) Char

func (*Font) LineHeight

func (f *Font) LineHeight() float32

func (*Font) Scales

func (f *Font) Scales() (float32, float32)

func (*Font) String

func (f *Font) String() string

type FontReader added in v0.4.0

type FontReader struct {
	// contains filtered or unexported fields
}

func NewFontReader added in v0.4.0

func NewFontReader() *FontReader

func (*FontReader) ReadFile added in v0.4.0

func (r *FontReader) ReadFile(filename string) (*Font, error)

type Info

type Info struct {
	Face     string // This is the name of the true type font.
	Size     int    // The size of the true type font.
	Bld      bool   // The font is bold.
	Italic   bool   // The font is italic.
	Charset  string // The name of the OEM charset used (when not unicode).
	Unicode  bool   // Set to 1 if it is the unicode charset.
	StretchH int    // The font height stretch in percentage. 100% means no stretch.
	Smooth   bool   // Set to 1 if smoothing was turned on.
	AA       int    // The supersampling level used. 1 means no supersampling was used.
	Padding  []int  // The padding for each character (up, right, down, left).
	Spacing  []int  // The spacing for each character (horizontal, vertical).
	Outline  int    // The outline thickness for the characters.
}

This tag holds information on how the font was generated.

type Kerning

type Kerning struct {
	First  uint8   // The first character id.
	Second uint8   // The second character id.
	Amount float32 // How much the x position should be adjusted when drawing the second character immediately following the first.
}

The kerning information is used to adjust the distance between certain characters, e.g. some characters should be placed closer to each other than others.

type OpenGLFont added in v0.5.0

type OpenGLFont struct {
	*Font
	// contains filtered or unexported fields
}

func NewOpenGLFont added in v0.5.0

func NewOpenGLFont(fntFilename, imageFilename string) (*OpenGLFont, error)

NewOpenGLFont createa a new font by reading the FNT and texture image file (PNG) This creates an OpenGL resource ; do not forget to call Delete() when no longer used.

func (*OpenGLFont) Delete added in v0.5.0

func (f *OpenGLFont) Delete()

type OpenGLTextureBuilder added in v0.5.0

type OpenGLTextureBuilder struct{}

func NewTextureBuilder added in v0.5.0

func NewTextureBuilder() OpenGLTextureBuilder

func (OpenGLTextureBuilder) BuildFromFile added in v0.5.0

func (r OpenGLTextureBuilder) BuildFromFile(filename string) (uint32, error)

type Page

type Page struct {
	Id   int    // The page id.
	File string // The texture file name.
}

This tag gives the name of a texture file. There is one for each page in the font.

type Text

type Text struct {
	X float32 // left-top x-coordinate
	Y float32 // left-top y-coordinate
	// contains filtered or unexported fields
}

func NewText

func NewText(text string, leftTopX, leftTopY, width, height float32, font *OpenGLFont) Text

NewText returns a new Text value for rendering a (multiline) string using a Font inside a 2D box. If the width is set to zero then the text will have a unscaled width computed from the text.

func (Text) Centered added in v0.7.0

func (t Text) Centered() Text

Centered returns a new text centered on its X and Y coordinate.

func (Text) Height

func (t Text) Height() float32

func (Text) Render

func (t Text) Render()

Render calls a function with 4 TextureVertex values per character. http://www.glprogramming.com/red/chapter09.html http://www.angelcode.com/products/bmfont/doc/render_text.html

func (Text) Width

func (t Text) Width() float32

type TextureVertex

type TextureVertex struct {
	S, T float32 // texture coordinates
	X, Y float32 // position coordinates
}

TextureVertex captures one corner of a character to render.

Jump to

Keyboard shortcuts

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