Created
March 18, 2024 21:44
-
-
Save laytan/6387f45f4f0558f5236eae4fe40c2a57 to your computer and use it in GitHub Desktop.
Odin GLFW 3.4 Hello World
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "core:log" | |
import "core:mem" | |
import "core:runtime" | |
import "vendor:glfw" | |
import gl "vendor:OpenGL" | |
main :: proc() { | |
context.logger = log.create_console_logger() | |
log_alloc: log.Log_Allocator | |
log.log_allocator_init(&log_alloc, .Debug, .Human, context.allocator) | |
context.allocator = log.log_allocator(&log_alloc) | |
ctx := context | |
allocator := glfw.Allocator{ | |
allocate = proc "c" (size: uint, user: rawptr) -> rawptr { | |
context = (^runtime.Context)(user)^ | |
ptr, err := mem.alloc(int(size)) | |
assert(err == nil) | |
return ptr | |
}, | |
reallocate = proc "c" (block: rawptr, size: uint, user: rawptr) -> rawptr { | |
context = (^runtime.Context)(user)^ | |
ptr, err := mem.resize(block, max(int), int(size)) | |
assert(err == nil) | |
return ptr | |
}, | |
deallocate = proc "c" (block: rawptr, user: rawptr) { | |
context = (^runtime.Context)(user)^ | |
err := mem.free(block) | |
assert(err == nil) | |
}, | |
user = &ctx, | |
} | |
glfw.InitAllocator(allocator) | |
assert(bool(glfw.Init())) | |
defer glfw.Terminate() | |
window := glfw.CreateWindow(640, 480, "My Title", nil, nil) | |
assert(window != nil) | |
defer glfw.DestroyWindow(window) | |
glfw.MakeContextCurrent(window) | |
gl.load_up_to(2, 0, glfw.gl_set_proc_address) | |
for !glfw.WindowShouldClose(window) { | |
width, height := glfw.GetFramebufferSize(window) | |
gl.Viewport(0, 0, width, height) | |
gl.Clear(gl.COLOR_BUFFER_BIT) | |
glfw.SwapBuffers(window) | |
glfw.PollEvents() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment