/
Application.go
executable file
·85 lines (76 loc) · 2.2 KB
/
Application.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package lux
import (
"github.com/go-gl/glfw/v3.1/glfw"
"github.com/luxengine/gl"
)
//obvious ryze quote
func letsglowLETSGLOW() {
// Initialize Glow
if err := gl.Init(); err != nil {
panic(err)
}
}
//SetContext will set a OpenGL core 3.3 context with foward compatibility and debug context
func SetContext() {
glfw.WindowHint(glfw.Resizable, glfw.False)
glfw.WindowHint(glfw.ContextVersionMajor, 3)
glfw.WindowHint(glfw.ContextVersionMinor, 3)
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True) // Necessary for OS X
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) // Necessary for OS X
glfw.WindowHint(glfw.OpenGLDebugContext, glfw.True)
}
func headlessContext() {
glfw.WindowHint(glfw.ContextVersionMajor, 3)
glfw.WindowHint(glfw.ContextVersionMinor, 3)
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True) // Necessary for OS X
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) // Necessary for OS X
glfw.WindowHint(glfw.OpenGLDebugContext, glfw.True)
glfw.WindowHint(glfw.Visible, glfw.False)
}
func glbs() {
//gl.Enable(gl.DEPTH_TEST)
//gl.DepthFunc(gl.LESS)
gl.ClearColor.Set(0.3, 0.3, 0.3, 1.0)
gl.CullFace.Enable()
}
//InitGLFW will call glfw.Init and panic if it fails
func InitGLFW() {
if err := glfw.Init(); err != nil {
panic("failed to initialize glfw")
}
}
//TerminateGLFW is an alias for glfw.Terminate
func TerminateGLFW() {
glfw.Terminate()
}
//CreateWindow creates a new glfw window. If fullscreen will place the screen on primary monitor.
func CreateWindow(width, height int, title string, fullscreen bool) (window *glfw.Window) {
SetContext()
var x *glfw.Monitor
if fullscreen {
x = glfw.GetPrimaryMonitor()
}
window, err := glfw.CreateWindow(width, height, title, x, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
letsglowLETSGLOW()
glbs()
QueryExtentions()
return
}
//StartHeadless will initialize everything but wont actually create a window, so you can test your application.
func StartHeadless() (window *glfw.Window) {
var err error
headlessContext()
window, err = glfw.CreateWindow(1, 1, "", nil, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
letsglowLETSGLOW()
glbs()
QueryExtentions()
return
}