fixed image drawing transformation
This commit is contained in:
parent
97dff96ca2
commit
63b71e5e52
3 changed files with 15 additions and 13 deletions
|
@ -18,7 +18,7 @@ type Backend interface {
|
||||||
|
|
||||||
Clear(pts [4][2]float64)
|
Clear(pts [4][2]float64)
|
||||||
Fill(style *FillStyle, pts [][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
|
FillImageMask(style *FillStyle, mask *image.Alpha, pts [][2]float64) // pts must have four points
|
||||||
|
|
||||||
ClearClip()
|
ClearClip()
|
||||||
|
|
|
@ -215,7 +215,7 @@ func (img *Image) Replace(src image.Image) error {
|
||||||
// have a full alpha value
|
// have a full alpha value
|
||||||
func (img *Image) IsOpaque() bool { return img.opaque }
|
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()
|
b.activate()
|
||||||
|
|
||||||
img := dimg.(*Image)
|
img := dimg.(*Image)
|
||||||
|
@ -225,19 +225,21 @@ func (b *GoGLBackend) DrawImage(dimg backendbase.Image, sx, sy, sw, sh, dx, dy,
|
||||||
sw /= float64(img.w)
|
sw /= float64(img.w)
|
||||||
sh /= float64(img.h)
|
sh /= float64(img.h)
|
||||||
|
|
||||||
|
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.StencilFunc(gl.EQUAL, 0, 0xFF)
|
||||||
|
|
||||||
gl.BindBuffer(gl.ARRAY_BUFFER, b.buf)
|
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),
|
|
||||||
float32(sx), float32(sy),
|
|
||||||
float32(sx), float32(sy + sh),
|
|
||||||
float32(sx + sw), float32(sy + sh),
|
|
||||||
float32(sx + sw), float32(sy),
|
|
||||||
}
|
|
||||||
gl.BufferData(gl.ARRAY_BUFFER, len(data)*4, unsafe.Pointer(&data[0]), gl.STREAM_DRAW)
|
gl.BufferData(gl.ARRAY_BUFFER, len(data)*4, unsafe.Pointer(&data[0]), gl.STREAM_DRAW)
|
||||||
|
|
||||||
gl.ActiveTexture(gl.TEXTURE0)
|
gl.ActiveTexture(gl.TEXTURE0)
|
||||||
|
|
|
@ -168,7 +168,7 @@ func (cv *Canvas) DrawImage(image interface{}, coords ...float64) {
|
||||||
|
|
||||||
cv.drawShadow2(data[:], nil)
|
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
|
// GetImageData returns an RGBA image of the current image
|
||||||
|
|
Loading…
Reference in a new issue