fixed image drawing transformation

This commit is contained in:
Thomas Friedel 2019-02-22 15:54:28 +01:00
parent 97dff96ca2
commit 63b71e5e52
3 changed files with 15 additions and 13 deletions

View file

@ -18,7 +18,7 @@ type Backend interface {
Clear(pts [4][2]float64)
Fill(style *FillStyle, pts [][2]float64)
DrawImage(dimg Image, sx, sy, sw, sh, dx, dy, dw, dh float64, alpha float64)
DrawImage(dimg Image, sx, sy, sw, sh float64, pts [4][2]float64, alpha float64)
FillImageMask(style *FillStyle, mask *image.Alpha, pts [][2]float64) // pts must have four points
ClearClip()

View file

@ -215,7 +215,7 @@ func (img *Image) Replace(src image.Image) error {
// have a full alpha value
func (img *Image) IsOpaque() bool { return img.opaque }
func (b *GoGLBackend) DrawImage(dimg backendbase.Image, sx, sy, sw, sh, dx, dy, dw, dh float64, alpha float64) {
func (b *GoGLBackend) DrawImage(dimg backendbase.Image, sx, sy, sw, sh float64, pts [4][2]float64, alpha float64) {
b.activate()
img := dimg.(*Image)
@ -225,19 +225,21 @@ func (b *GoGLBackend) DrawImage(dimg backendbase.Image, sx, sy, sw, sh, dx, dy,
sw /= float64(img.w)
sh /= float64(img.h)
gl.StencilFunc(gl.EQUAL, 0, 0xFF)
gl.BindBuffer(gl.ARRAY_BUFFER, b.buf)
data := [16]float32{
float32(dx), float32(dy),
float32(dx), float32(dy + dh),
float32(dx + dw), float32(dy + dh),
float32(dx + dw), float32(dy),
var buf [16]float32
data := buf[:0]
for _, pt := range pts {
data = append(data, float32(pt[0]), float32(pt[1]))
}
data = append(data,
float32(sx), float32(sy),
float32(sx), float32(sy+sh),
float32(sx+sw), float32(sy+sh),
float32(sx+sw), float32(sy),
}
)
gl.StencilFunc(gl.EQUAL, 0, 0xFF)
gl.BindBuffer(gl.ARRAY_BUFFER, b.buf)
gl.BufferData(gl.ARRAY_BUFFER, len(data)*4, unsafe.Pointer(&data[0]), gl.STREAM_DRAW)
gl.ActiveTexture(gl.TEXTURE0)

View file

@ -168,7 +168,7 @@ func (cv *Canvas) DrawImage(image interface{}, coords ...float64) {
cv.drawShadow2(data[:], nil)
cv.b.DrawImage(img.img, sx, sy, sw, sh, dx, dy, dw, dh, cv.state.globalAlpha)
cv.b.DrawImage(img.img, sx, sy, sw, sh, data, cv.state.globalAlpha)
}
// GetImageData returns an RGBA image of the current image