graphics: Bug fix #186 by clearing non-black-or-white color

This commit is contained in:
Hajime Hoshi 2016-03-17 03:31:12 +09:00
parent 6c78837d06
commit b02df7b542
3 changed files with 12 additions and 7 deletions

View File

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

View File

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

View File

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