Beispiel #1
0
func (cfg *Config) Texture(rend *sdl.Renderer, key string) *sdl.Texture {
	surface := sdl.Load(cfg.data[key])
	if surface == nil {
		log.Fatal("Failed to load " + cfg.data[key])
	}
	defer surface.Free()
	return rend.CreateTextureFromSurface(surface)
}
Beispiel #2
0
func RenderTextToTexture(r *sdl.Renderer, f *ttf.Font, text string, color sdl.Color) (*sdl.Texture, int, int) {
	textw, texth, err := f.SizeText(text)
	if err != nil {
		log.Fatal(err)
	}
	txt_surface := f.RenderText_Blended(text, color)
	txt_tex := r.CreateTextureFromSurface(txt_surface)
	txt_surface.Free()
	return txt_tex, textw, texth
}
Beispiel #3
0
func (label *Label) Update(rend *sdl.Renderer) {
	textw, texth, err := label.Font.SizeText(label.Text)
	if err != nil {
		log.Fatal(err)
	}
	txt_surface := label.Font.RenderText_Blended(label.Text, label.Color)
	if label.texture != nil {
		label.texture.Destroy()
	}
	label.texture = rend.CreateTextureFromSurface(txt_surface)
	txt_surface.Free()
	label.texwidth = int32(textw)
	label.texheight = int32(texth)
}