SDL surface is created from non-alpha-premultiplied colors.

This commit is contained in:
Sander Schobers 2020-05-20 19:45:16 +02:00
parent 0fe9a2ce63
commit 39766e9f01
2 changed files with 12 additions and 1 deletions

View File

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

View File

@ -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
}