SetBounds on GL backend now sets the viewport right away; updated drawing example

This commit is contained in:
Thomas Friedel 2019-02-24 11:01:25 +01:00
parent a36c635367
commit c207447158
2 changed files with 5 additions and 7 deletions

View file

@ -233,6 +233,9 @@ func (b *GoGLBackend) SetBounds(x, y, w, h int) {
}
b.w, b.h = w, h
b.fw, b.fh = float64(w), float64(h)
if b == activeContext {
gl.Viewport(0, 0, int32(b.w), int32(b.h))
}
}
func (b *GoGLBackend) Size() (int, int) {

View file

@ -5,7 +5,6 @@ import (
"log"
"math"
"github.com/tfriedel6/canvas"
"github.com/tfriedel6/canvas/sdlcanvas"
)
@ -17,20 +16,16 @@ func main() {
}
defer wnd.Destroy()
lg := canvas.NewLinearGradient(320, 200, 480, 520)
lg := cv.CreateLinearGradient(320, 200, 480, 520)
lg.AddColorStop(0, "#ff000040")
lg.AddColorStop(1, "#00ff0040")
lg.AddColorStop(0.5, "#0000ff40")
rg := canvas.NewRadialGradient(540, 300, 80, 740, 300, 100)
rg := cv.CreateRadialGradient(540, 300, 80, 740, 300, 100)
rg.AddColorStop(0, "#ff0000")
rg.AddColorStop(1, "#00ff00")
rg.AddColorStop(0.5, "#0000ff")
wnd.SizeChange = func(w, h int) {
cv.SetBounds(0, 0, w, h)
}
wnd.MainLoop(func() {
w, h := float64(cv.Width()), float64(cv.Height())