Hello everyone, I’m a first time dev in Odin and I wanted to get some quick feedback on what I wrote just now to know if I’m missing something about idiomatic Odin or if I’ve made an obvious mistake with my way of structuring code. What I got from the guidelines is “Have fun and code great things”, but I think there still might be untold “best practices” and I would be happy to have feedback on that, even tho I’m not sure I’ll keep everything, after all, I’m here to have fun. Here is the code (Just a cornflower blue window in glfw / OpenGL the way I would write it in C):
package main
import "vendor:OpenGL"
import "core:os"
import "core:fmt"
import "vendor:glfw"
init_window :: proc() -> glfw.WindowHandle {
if !glfw.Init() {
fmt.eprintln(os.args[0], ": Unable to initialize GLFW")
return nil
}
window := glfw.CreateWindow(720, 360, "test", nil, nil)
if window == nil {
fmt.eprintln(os.args[0], ": Unable to open a GLFW window")
glfw.Terminate()
return nil
}
glfw.MakeContextCurrent(window)
OpenGL.load_up_to(3, 3, glfw.gl_set_proc_address)
OpenGL.ClearColor(0.392, 0.584, 0.929, 1.0)
return window
}
update_window :: proc(window: glfw.WindowHandle) {
OpenGL.Clear(OpenGL.COLOR_BUFFER_BIT)
glfw.SwapBuffers(window)
glfw.PollEvents()
}
run :: proc() -> int {
window := init_window()
if window == nil {
return 1
}
defer glfw.Terminate()
defer glfw.DestroyWindow(window)
for !glfw.WindowShouldClose(window) {
update_window(window)
}
return 0
}
main :: proc() {
os.exit(run())
}
Thanks for reading this brick and thank you even more if you answer this. Have a nice rest of your day.