/
loader.go
51 lines (42 loc) · 1.02 KB
/
loader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"golang.org/x/mobile/asset"
"image"
"image/draw"
_ "image/png"
"golang.org/x/mobile/exp/gl/glutil"
"golang.org/x/mobile/gl"
"io/ioutil"
)
func loadImages(path string) *image.RGBA {
// allocating image holder
var img image.Image
imgFile, e := asset.Open(path)
def_check(e)
defer imgFile.Close()
// decoding image
img, _, e = image.Decode(imgFile)
def_check(e)
// pure rgbaing
rgba := image.NewRGBA(img.Bounds())
draw.Draw(rgba, rgba.Bounds(), img, image.Point{0, 0}, draw.Src)
return rgba
}
func loadSource(path string) ([]byte, error) {
sourceFile, e := asset.Open(path)
defer sourceFile.Close()
def_check(e)
return ioutil.ReadAll(sourceFile)
}
func createProgram(vShaderPath, fShaderPath string) gl.Program {
// loading vertex shader
vShader, e := loadSource(vShaderPath)
def_check(e)
// loading fragment shader
fShader, e := loadSource(fShaderPath)
def_check(e)
// linking program
program, e := glutil.CreateProgram(string(vShader), string(fShader))
crash_check(e)
return program
}