/
main.go
131 lines (81 loc) · 2.61 KB
/
main.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* REFACTORING OF GOLANG-VR-LINUX TO SUPPORT A MORE ROBUST DEVELOPMENT PIPELINE
STILL BASICALLY IDENTICAL TO LEGACY VERSION, REFACTORING TO COME AFTER OPENGL
CALLS ARE MADE
*/
package main
//Let's try importing the ovr c library
/*
#cgo CFLAGS: -I/usr/local/include
#cgo LDFLAGS: -L/usr/lib/ -L/usr/local/lib/ -lovr -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lrt -lGL -lm -lstdc++
#include <OVR_CAPI.h>
#include <OVR_CAPI_GL.h>
*/
import "C"
import (
"fmt"
"runtime"
"log"
"./engine"
"github.com/go-gl/gl/v4.5-core/gl"
"github.com/go-gl/glfw/v3.1/glfw"
//"github.com/go-gl/mathgl/mgl32"
"./common" //This includes some shader loaders and program binding functions
// "./ovr" //Go wrapper for common OVR functions
)
var firstSprite engine.Sprite
func init() {
runtime.LockOSThread() //allows for OpenGL
}
/* ***************** MAIN FUNCTION ************************ */
func main() {
if err:=glfw.Init(); err != nil {
log.Fatalln("failed to initialize glfw")
}
defer glfw.Terminate()
// ************* OPENGL / GLFW INIT CODE ************** */
glfw.WindowHint(glfw.Decorated, 0)
glfw.WindowHint(glfw.Resizable, glfw.False)
glfw.WindowHint(glfw.ContextVersionMajor, 4)
glfw.WindowHint(glfw.ContextVersionMinor, 1)
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
window, err := glfw.CreateWindow(1000, 1000, "GoGL", nil, nil)
if gl.Init(); err != nil {
panic(err)
}
window.MakeContextCurrent();
//Print OpenGL Version to console
version := gl.GoStr(gl.GetString(gl.VERSION))
fmt.Println("OpenGL Version", version, "\n\n")
//keyboard input callback
window.SetKeyCallback(onKey);
spriteprogram := common.LoadShaderProgram("./shaders/vertexShader", "./shaders/fragmentShader")
firstSprite.Init(-0.25,-0.25,0.5,0.5,spriteprogram)
/* ******************* MAIN LOOP ******************** */
for !window.ShouldClose() {
update()
render(window, spriteprogram);
//Poll for events (keyboard, resize, etc)
}
}
func update() {
}
func render(w *glfw.Window, program uint32) {
gl.ClearColor(0,0,0,1)
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
gl.UseProgram(program)
gl.BindVertexArray(firstSprite.GetVAO())
gl.DrawArrays(gl.TRIANGLES, 0, 6)
//Swap buffers
w.SwapBuffers()
glfw.PollEvents()
gl.UseProgram(0)
}
/* ***************** KEYBOARD INPUT ******************** */
func onKey(w *glfw.Window, key glfw.Key, scancode int,
action glfw.Action, mods glfw.ModifierKey) {
if key == glfw.KeyEscape && action == glfw.Press {
fmt.Println("Close Window")
w.SetShouldClose(true)
}
}