glfw/window

Code

simple_window.odin ¶
45 linesSource

1package glfw_window
2
3import "core:fmt"
4import "vendor:glfw"
5import gl "vendor:OpenGL"
6
7WIDTH  	:: 1600
8HEIGHT 	:: 900
9TITLE 	:: "My Window!"
10
11// @note You might need to lower this to 3.3 depending on how old your graphics card is.
12GL_MAJOR_VERSION :: 4
13GL_MINOR_VERSION :: 5
14
15main :: proc() {
16	if !bool(glfw.Init()) {
17		fmt.eprintln("GLFW has failed to load.")
18		return
19	}
20
21	window_handle := glfw.CreateWindow(WIDTH, HEIGHT, TITLE, nil, nil)
22
23	defer glfw.Terminate()
24	defer glfw.DestroyWindow(window_handle)
25
26	if window_handle == nil {
27		fmt.eprintln("GLFW has failed to load the window.")
28		return
29	}
30
31	// Load OpenGL context or the "state" of OpenGL.
32	glfw.MakeContextCurrent(window_handle)
33	// Load OpenGL function pointers with the specficed OpenGL major and minor version.
34	gl.load_up_to(GL_MAJOR_VERSION, GL_MINOR_VERSION, glfw.gl_set_proc_address)
35
36	for !glfw.WindowShouldClose(window_handle) {
37		// Process all incoming events like keyboard press, window resize, and etc.
38		glfw.PollEvents()
39
40		gl.ClearColor(0.5, 0.0, 1.0, 1.0)
41		gl.Clear(gl.COLOR_BUFFER_BIT)
42
43		glfw.SwapBuffers(window_handle)
44	}
45}

Declarations Used 14