From 39766e9f01965786c689716c7c42f190a608244a Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Wed, 20 May 2020 19:45:16 +0200 Subject: [PATCH] SDL surface is created from non-alpha-premultiplied colors. --- sdlui/image.go | 10 ++++++++++ sdlui/renderer.go | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) 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 }