From f8ff288aac88eef0d89e2d48032c3c57be7dc315 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Sun, 3 Nov 2024 17:40:17 -0500 Subject: [PATCH 1/3] all: update dependencies Use the latest versions of go-gl dependencies in this example module. Update to a currently supported version of Go. At least Go 1.16 will be needed in the next commit to use go:embed feature. --- go.mod | 9 ++++----- go.sum | 16 ++++++---------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 4144cfa..c399419 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,9 @@ module github.com/go-gl/example -go 1.14 +go 1.22.0 require ( - github.com/go-gl/gl v0.0.0-20210426225639-a3bfa832c8aa - github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb - github.com/go-gl/mathgl v1.0.0 - golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect + github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 + github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a + github.com/go-gl/mathgl v1.2.0 ) diff --git a/go.sum b/go.sum index d30eda9..2f005c7 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,6 @@ -github.com/go-gl/gl v0.0.0-20210426225639-a3bfa832c8aa h1:yiL6tST9ZuWBXiymIdM0j6yeLwMVGXDoybpXqnbJpCk= -github.com/go-gl/gl v0.0.0-20210426225639-a3bfa832c8aa/go.mod h1:wjpnOv6ONl2SuJSxqCPVaPZibGFdSci9HFocT9qtVYM= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb h1:T6gaWBvRzJjuOrdCtg8fXXjKai2xSDqWTcKFUPuw8Tw= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-gl/mathgl v1.0.0 h1:t9DznWJlXxxjeeKLIdovCOVJQk/GzDEL7h/h+Ro2B68= -github.com/go-gl/mathgl v1.0.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ= -golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb h1:fqpd0EBDzlHRCjiphRR5Zo/RSWWQlWv34418dnEixWk= -golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 h1:5BVwOaUSBTlVZowGO6VZGw2H/zl9nrd3eCZfYV+NfQA= +github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+xzxf1jTJKMKZw3H0swfWk9RpWbBbDK5+0= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/mathgl v1.2.0 h1:v2eOj/y1B2afDxF6URV1qCYmo1KW08lAMtTbOn3KXCY= +github.com/go-gl/mathgl v1.2.0/go.mod h1:pf9+b5J3LFP7iZ4XXaVzZrCle0Q/vNpB/vDe5+3ulRE= From 7dda5e165f25df5a74eb8049e0ded8f423fb21b1 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Sun, 3 Nov 2024 17:42:18 -0500 Subject: [PATCH 2/3] all: embed texture file This makes the result binary more portable. It can be copied to another machine where the source code isn't present and still run okay. Relying on the go/build package and GOPATH to find assets was the best we could do before the module mode. Fixes #85. --- gl21-cube/cube.go | 33 ++++++--------------------------- gl41core-cube/cube.go | 33 ++++++--------------------------- 2 files changed, 12 insertions(+), 54 deletions(-) diff --git a/gl21-cube/cube.go b/gl21-cube/cube.go index 4416ee9..95233df 100644 --- a/gl21-cube/cube.go +++ b/gl21-cube/cube.go @@ -2,16 +2,15 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Renders a textured spinning cube using GLFW 3 and OpenGL 2.1. -package main // import "github.com/go-gl/example/gl21-cube" +// gl21-cube renders a textured spinning cube using GLFW 3 and OpenGL 2.1. +package main import ( - "go/build" + "embed" "image" "image/draw" _ "image/png" "log" - "os" "runtime" "github.com/go-gl/gl/v2.1/gl" @@ -62,7 +61,7 @@ func main() { } func newTexture(file string) uint32 { - imgFile, err := os.Open(file) + imgFile, err := assetFS.Open(file) if err != nil { log.Fatalf("texture %q not found on disk: %v\n", file, err) } @@ -204,25 +203,5 @@ func drawScene() { gl.End() } -// Set the working directory to the root of Go package, so that its assets can be accessed. -func init() { - dir, err := importPathToDir("github.com/go-gl/example/gl21-cube") - if err != nil { - log.Fatalln("Unable to find Go package in your GOPATH, it's needed to load assets:", err) - } - err = os.Chdir(dir) - if err != nil { - log.Panicln("os.Chdir:", err) - } -} - -// importPathToDir resolves the absolute path from importPath. -// There doesn't need to be a valid Go package inside that import path, -// but the directory must exist. -func importPathToDir(importPath string) (string, error) { - p, err := build.Import(importPath, "", build.FindOnly) - if err != nil { - return "", err - } - return p.Dir, nil -} +//go:embed square.png +var assetFS embed.FS diff --git a/gl41core-cube/cube.go b/gl41core-cube/cube.go index 0f32200..031187b 100644 --- a/gl41core-cube/cube.go +++ b/gl41core-cube/cube.go @@ -2,17 +2,16 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Renders a textured spinning cube using GLFW 3 and OpenGL 4.1 core forward-compatible profile. -package main // import "github.com/go-gl/example/gl41core-cube" +// gl41core-cube renders a textured spinning cube using GLFW 3 and OpenGL 4.1 core forward-compatible profile. +package main import ( + "embed" "fmt" - "go/build" "image" "image/draw" _ "image/png" "log" - "os" "runtime" "strings" @@ -198,7 +197,7 @@ func compileShader(source string, shaderType uint32) (uint32, error) { } func newTexture(file string) (uint32, error) { - imgFile, err := os.Open(file) + imgFile, err := assetFS.Open(file) if err != nil { return 0, fmt.Errorf("texture %q not found on disk: %v", file, err) } @@ -318,25 +317,5 @@ var cubeVertices = []float32{ 1.0, 1.0, 1.0, 0.0, 1.0, } -// Set the working directory to the root of Go package, so that its assets can be accessed. -func init() { - dir, err := importPathToDir("github.com/go-gl/example/gl41core-cube") - if err != nil { - log.Fatalln("Unable to find Go package in your GOPATH, it's needed to load assets:", err) - } - err = os.Chdir(dir) - if err != nil { - log.Panicln("os.Chdir:", err) - } -} - -// importPathToDir resolves the absolute path from importPath. -// There doesn't need to be a valid Go package inside that import path, -// but the directory must exist. -func importPathToDir(importPath string) (string, error) { - p, err := build.Import(importPath, "", build.FindOnly) - if err != nil { - return "", err - } - return p.Dir, nil -} +//go:embed square.png +var assetFS embed.FS From 94a61ac917fc1c52c11802929a8c2334b24101e8 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Sun, 3 Nov 2024 17:50:58 -0500 Subject: [PATCH 3/3] .github/workflows: test with Go 1.23, 1.22 These are the currently supported major Go versions. --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c91739e..36ab5ed 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,13 +1,12 @@ name: Main on: [push, pull_request] jobs: - tests: name: ${{matrix.go-version}} ${{matrix.os}} runs-on: ${{ matrix.os }} strategy: matrix: - go-version: [1.14, 1.16] + go-version: [1.23, 1.22] os: [macos-latest, windows-latest, ubuntu-latest] steps: - name: Install dependencies (linux)