diff --git a/sdlui/image.go b/sdlui/image.go index 3e29bc0..669ed3b 100644 --- a/sdlui/image.go +++ b/sdlui/image.go @@ -5,6 +5,16 @@ import ( "image/draw" ) +func NRGBAImage(m image.Image) *image.NRGBA { + nrgba, ok := m.(*image.NRGBA) + if ok { + return nrgba + } + nrgba = image.NewNRGBA(m.Bounds()) + draw.Draw(nrgba, nrgba.Bounds(), m, image.ZP, draw.Over) + return nrgba +} + func RGBAImage(m image.Image) *image.RGBA { rgba, ok := m.(*image.RGBA) if ok { diff --git a/sdlui/renderer.go b/sdlui/renderer.go index 9242502..7d4ef86 100644 --- a/sdlui/renderer.go +++ b/sdlui/renderer.go @@ -243,7 +243,7 @@ func (r *Renderer) createTexture(source ui.ImageSource, keepSource bool) (ui.Tex if err != nil { return nil, err } - rgba := RGBAImage(m) + rgba := NRGBAImage(m) width := int32(rgba.Bounds().Dx()) height := int32(rgba.Bounds().Dy()) surface, err := sdl.CreateRGBSurfaceWithFormatFrom( @@ -257,6 +257,7 @@ func (r *Renderer) createTexture(source ui.ImageSource, keepSource bool) (ui.Tex if err != nil { return nil, err } + texture.SetBlendMode(sdl.BLENDMODE_BLEND) if keepSource { return &TextureImageSource{&Texture{texture}, source}, nil }