|
2 | 2 | // Use of this source code is governed by a BSD-style
|
3 | 3 | // license that can be found in the LICENSE file.
|
4 | 4 |
|
5 |
| -// Renders a textured spinning cube using GLFW 3 and OpenGL 4.1 core forward-compatible profile. |
6 |
| -package main // import "github.com/go-gl/example/gl41core-cube" |
| 5 | +// gl41core-cube renders a textured spinning cube using GLFW 3 and OpenGL 4.1 core forward-compatible profile. |
| 6 | +package main |
7 | 7 |
|
8 | 8 | import (
|
| 9 | + "embed" |
9 | 10 | "fmt"
|
10 |
| - "go/build" |
11 | 11 | "image"
|
12 | 12 | "image/draw"
|
13 | 13 | _ "image/png"
|
14 | 14 | "log"
|
15 |
| - "os" |
16 | 15 | "runtime"
|
17 | 16 | "strings"
|
18 | 17 |
|
@@ -198,7 +197,7 @@ func compileShader(source string, shaderType uint32) (uint32, error) {
|
198 | 197 | }
|
199 | 198 |
|
200 | 199 | func newTexture(file string) (uint32, error) {
|
201 |
| - imgFile, err := os.Open(file) |
| 200 | + imgFile, err := assetFS.Open(file) |
202 | 201 | if err != nil {
|
203 | 202 | return 0, fmt.Errorf("texture %q not found on disk: %v", file, err)
|
204 | 203 | }
|
@@ -318,25 +317,5 @@ var cubeVertices = []float32{
|
318 | 317 | 1.0, 1.0, 1.0, 0.0, 1.0,
|
319 | 318 | }
|
320 | 319 |
|
321 |
| -// Set the working directory to the root of Go package, so that its assets can be accessed. |
322 |
| -func init() { |
323 |
| - dir, err := importPathToDir("github.com/go-gl/example/gl41core-cube") |
324 |
| - if err != nil { |
325 |
| - log.Fatalln("Unable to find Go package in your GOPATH, it's needed to load assets:", err) |
326 |
| - } |
327 |
| - err = os.Chdir(dir) |
328 |
| - if err != nil { |
329 |
| - log.Panicln("os.Chdir:", err) |
330 |
| - } |
331 |
| -} |
332 |
| - |
333 |
| -// importPathToDir resolves the absolute path from importPath. |
334 |
| -// There doesn't need to be a valid Go package inside that import path, |
335 |
| -// but the directory must exist. |
336 |
| -func importPathToDir(importPath string) (string, error) { |
337 |
| - p, err := build.Import(importPath, "", build.FindOnly) |
338 |
| - if err != nil { |
339 |
| - return "", err |
340 |
| - } |
341 |
| - return p.Dir, nil |
342 |
| -} |
| 320 | +//go:embed square.png |
| 321 | +var assetFS embed.FS |
0 commit comments