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
|
package main
import gl "vendor:OpenGL"
import "vendor:glfw"
import "base:intrinsics"
import "base:runtime"
import "core:fmt"
GL_MAJOR_VERSION :: 3
GL_MINOR_VERSION :: 3
framebuffer_size_callback :: proc "cdecl" (window: glfw.WindowHandle, width, height: i32) {
gl.Viewport(0, 0, width, height)
}
process_input :: proc(window: ^glfw.WindowHandle) {
if glfw.GetKey(window^, glfw.KEY_ESCAPE) == glfw.PRESS {
glfw.SetWindowShouldClose(window^, true)
}
}
main :: proc() {
glfw.Init()
glfw.WindowHint(glfw.CONTEXT_VERSION_MAJOR, GL_MAJOR_VERSION)
glfw.WindowHint(glfw.CONTEXT_VERSION_MINOR, GL_MINOR_VERSION)
glfw.WindowHint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
when ODIN_OS == .Darwin {
glfw.WindowHint(glfw.OPENGL_FORWARD_COMPAT, gl.TRUE)
}
window := glfw.CreateWindow(800, 600, "Funhalla Engine", nil, nil)
defer glfw.Terminate()
defer glfw.DestroyWindow(window)
if window == nil {
fmt.eprintln("Failed to create GLFW window")
return
}
glfw.MakeContextCurrent(window)
gl.load_up_to(GL_MAJOR_VERSION, GL_MINOR_VERSION, glfw.gl_set_proc_address)
gl.Viewport(0, 0, 800, 600)
glfw.SetFramebufferSizeCallback(window, framebuffer_size_callback)
for !glfw.WindowShouldClose(window) {
process_input(&window)
gl.ClearColor(0.2, 0.3, 0.3, 1.0)
gl.Clear(gl.COLOR_BUFFER_BIT)
glfw.SwapBuffers(window)
glfw.PollEvents()
}
}
|