mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
graphics: Bug fix #186 by clearing non-black-or-white color
This commit is contained in:
parent
6c78837d06
commit
b02df7b542
2
image.go
2
image.go
@ -179,7 +179,7 @@ func (i *Image) ReplacePixels(p []uint8) error {
|
||||
if len(p) != l {
|
||||
return errors.New(fmt.Sprintf("p's length must be %d", l))
|
||||
}
|
||||
return i.texture.ReplacePixels(glContext, p)
|
||||
return i.framebuffer.ReplacePixels(glContext, i.texture, p)
|
||||
}
|
||||
|
||||
// A DrawImageOptions represents options to render an image on an image.
|
||||
|
@ -129,3 +129,14 @@ func (f *Framebuffer) Pixels(c *opengl.Context) ([]uint8, error) {
|
||||
w, h = int(NextPowerOf2Int32(int32(w))), int(NextPowerOf2Int32(int32(h)))
|
||||
return c.FramebufferPixels(f.native, w, h)
|
||||
}
|
||||
|
||||
func (f *Framebuffer) ReplacePixels(c *opengl.Context, t *Texture, p []uint8) error {
|
||||
// Filling with non black or white color is required here for glTexSubImage2D.
|
||||
// Very mysterious but this actually works (Issue #186)
|
||||
if err := f.Fill(c, color.RGBA{0, 0, 0x01, 0xff}); err != nil {
|
||||
return err
|
||||
}
|
||||
c.BindTexture(t.native)
|
||||
c.TexSubImage2D(p, t.width, t.height)
|
||||
return nil
|
||||
}
|
||||
|
@ -89,9 +89,3 @@ func NewTextureFromImage(c *opengl.Context, img image.Image, filter opengl.Filte
|
||||
func (t *Texture) Dispose(c *opengl.Context) {
|
||||
c.DeleteTexture(t.native)
|
||||
}
|
||||
|
||||
func (t *Texture) ReplacePixels(c *opengl.Context, p []uint8) error {
|
||||
c.BindTexture(t.native)
|
||||
c.TexSubImage2D(p, t.width, t.height)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user