diff --git a/canvas/texture.go b/canvas/texture.go index 27747c0..f923087 100644 --- a/canvas/texture.go +++ b/canvas/texture.go @@ -74,6 +74,11 @@ func (t *Texture) Size() render.Rect { return render.NewRect(t.width, t.height) } +// Image returns the underlying image. +func (t *Texture) Image() image.Image { + return nil +} + // LoadTexture recalls a cached texture image. func (e *Engine) LoadTexture(name string) (render.Texturer, error) { if tex, ok := e.textures[name]; ok { diff --git a/interface.go b/interface.go index 377ec81..e1e7eca 100644 --- a/interface.go +++ b/interface.go @@ -49,6 +49,7 @@ type Engine interface { // abstracting away its inner workings. type Texturer interface { Size() Rect + Image() image.Image } // Rect has a coordinate and a width and height. diff --git a/sdl/texture.go b/sdl/texture.go index 09966ab..74142c6 100644 --- a/sdl/texture.go +++ b/sdl/texture.go @@ -24,6 +24,7 @@ func (r *Renderer) Copy(t render.Texturer, src, dst render.Rect) { // Texture can hold on to SDL textures for caching and optimization. type Texture struct { tex *sdl.Texture + image image.Image width int32 height int32 } @@ -64,6 +65,7 @@ func (r *Renderer) StoreTexture(name string, img image.Image) (render.Texturer, width: surface.W, height: surface.H, tex: texture, + image: img, } r.textures[name] = tex @@ -75,6 +77,11 @@ func (t *Texture) Size() render.Rect { return render.NewRect(int(t.width), int(t.height)) } +// Image returns the underlying Go image.Image. +func (t *Texture) Image() image.Image { + return t.image +} + // LoadTexture initializes a texture from a bitmap image. func (r *Renderer) LoadTexture(name string) (render.Texturer, error) { if tex, ok := r.textures[name]; ok {