/
window.go
36 lines (28 loc) · 875 Bytes
/
window.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
package sprite
import (
"github.com/go-gl-legacy/gl"
glfw "github.com/go-gl/glfw3/v3.0/glfw"
"log"
"runtime"
)
func OpenWindow(width, height int, caption string) *glfw.Window {
// OpenGL haluaa että sitä käytetään aina samasta threadista
// muuten tulee satunnaisia segfaultteja
runtime.LockOSThread()
glfw.Init()
// luodaan ikkuna
w, err := glfw.CreateWindow(width, height, caption, nil, nil)
if err != nil {
log.Fatal(err)
}
w.MakeContextCurrent()
gl.Init()
// Jotta painalluksista kerrottaisiin vaikka ne olisivat jo päättyneet
w.SetInputMode(glfw.StickyKeys, glfw.True)
w.SetInputMode(glfw.StickyMouseButtons, glfw.True)
// läpinäkyvyys päälle (non-premultiplied alpha)
gl.Enable(gl.BLEND)
gl.BlendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD)
gl.BlendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ZERO)
return w
}