Пример #1
0
func (h *HGE) Texture_Load(filename string, a ...interface{}) *gfx.Texture {
	return gfx.LoadTexture(filename, a...)
}
Пример #2
0
func New(filename string, arg ...interface{}) *Font {
	mipmap := false

	if len(arg) == 1 {
		if m, ok := arg[0].(bool); ok {
			mipmap = m
		}
	}

	f := new(Font)

	h := hge.New()

	f.scale, f.proportion = 1.0, 1.0
	f.spacing = 1.0

	f.z = 0.5
	f.blend = gfx.BLEND_COLORMUL | gfx.BLEND_ALPHABLEND | gfx.BLEND_NOZWRITE
	f.color = 0xFFFFFFFF

	desc := resource.LoadString(filename)

	if desc == nil {
		h.Log("Font %s seems to be empty.", filename)
		return nil
	}

	lines := getLines(*desc)

	if len(lines) == 0 || lines[0] != fntHEADERTAG {
		h.Log("Font %s has incorrect format.", filename)
		return nil
	}

	// parse the font description
	for _, line := range lines {
		if line == fntHEADERTAG {
			continue
		}

		option, value, err := tokenizeLine(line)

		if err != nil || len(line) == 0 || len(option) == 0 || len(value) == 0 {
			h.Log("Unreadable line (%s) in font file: %s", line, filename)
			continue
		}

		if option == fntBITMAPTAG {
			f.texture = gfx.LoadTexture(value, 0, mipmap)
		} else if option == fntCHARTAG {
			chr, x, y, w, h, a, c := tokenizeChar(value)

			sprt := sprite.New(f.texture, x, y, w, h)

			f.letters[chr] = &sprt
			f.pre[chr] = a
			f.post[chr] = c
			f.height = h
		}
	}

	return f
}