40 lines
737 B
Go
40 lines
737 B
Go
|
package tins2020
|
||
|
|
||
|
import (
|
||
|
"github.com/veandco/go-sdl2/img"
|
||
|
"github.com/veandco/go-sdl2/sdl"
|
||
|
)
|
||
|
|
||
|
type Textures struct {
|
||
|
renderer *sdl.Renderer
|
||
|
textures map[string]*sdl.Texture
|
||
|
}
|
||
|
|
||
|
func (t *Textures) Init(renderer *sdl.Renderer) {
|
||
|
t.renderer = renderer
|
||
|
t.textures = map[string]*sdl.Texture{}
|
||
|
}
|
||
|
|
||
|
func (t *Textures) Load(name, path string, size int) error {
|
||
|
surface, err := img.Load(name)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer surface.Free()
|
||
|
texture, err := t.renderer.CreateTextureFromSurface(surface)
|
||
|
if t.textures == nil {
|
||
|
t.textures = map[string]*sdl.Texture{}
|
||
|
}
|
||
|
t.textures[name] = texture
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (t *Textures) Destroy() {
|
||
|
if t.textures == nil {
|
||
|
return
|
||
|
}
|
||
|
for _, t := range t.textures {
|
||
|
t.Destroy()
|
||
|
}
|
||
|
}
|