diff --git a/examples/web/galaxy.png b/examples/web/galaxy.png new file mode 100755 index 0000000..8f860ca Binary files /dev/null and b/examples/web/galaxy.png differ diff --git a/examples/web/main.go b/examples/web/main.go new file mode 100644 index 0000000..09ad480 --- /dev/null +++ b/examples/web/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "embed" + + vuelto "vuelto.pp.ua/pkg" +) + +//go:embed tree.png galaxy.png +var embeddedFiles embed.FS + +func main() { + // This works in the web too! This is because of the images being embedded! + w := vuelto.NewWindow("Image Example - Vuelto", 800, 600, false) + ren := w.NewRenderer2D() + + iembed := vuelto.ImageEmbed{ + Filesystem: embeddedFiles, + Image: "tree.png", + } + + i2embed := vuelto.ImageEmbed{ + Filesystem: embeddedFiles, + Image: "galaxy.png", + } + + image1 := ren.LoadImage(iembed, 0.5, 0.5, -0.5, 0.5) + image := ren.LoadImage(i2embed, 0, 0, 1, 1) + rect := ren.NewRect(0, 0, -1, -1, [4]int{10, 145, 245, 255}) + rect2 := ren.NewRect(0, 1, 1, 1, [4]int{245, 145, 10, 255}) + line := ren.NewLine(0.5, 0.5, -0.5, -0.5, [4]int{10, 145, 245, 255}) + + for !w.Close() { + ren.ClearColor([4]int{100, 100, 100, 255}) + ren.DrawLine(-0.9, -0.9, 0.9, -0.9, [4]int{10, 145, 245, 255}) + + rect.Draw() + rect2.Draw() + line.Draw() + + image1.Draw() + image.Draw() + w.Refresh() + } +} diff --git a/examples/web/tree.png b/examples/web/tree.png new file mode 100755 index 0000000..36d2211 Binary files /dev/null and b/examples/web/tree.png differ diff --git a/internal/window/win_web.go b/internal/window/win_web.go index b0725c4..9e1b755 100755 --- a/internal/window/win_web.go +++ b/internal/window/win_web.go @@ -139,7 +139,7 @@ func (w *Window) Destroy() {} func (w *Window) HandleEvents() { now := time.Now() - w.deltaTime = now.Sub(w.lastTime).Seconds() + w.deltaTime = float32(now.Sub(w.lastTime).Seconds()) w.lastTime = now duration := time.Since(w.lastTime)