Browse Source

Texturer to hold raw Go image.Image

master
Noah Petherbridge 6 months ago
parent
commit
d77f5056b7
  1. 5
      canvas/texture.go
  2. 1
      interface.go
  3. 7
      sdl/texture.go

5
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 {

1
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.

7
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 {

Loading…
Cancel
Save