Skip to content

Instantly share code, notes, and snippets.

// Sample code showing how to create a modern OpenGL window and rendering
// context on Win32, using Odin.
//
// Ported from https://gist.github.com/nickrolfe/1127313ed1dbf80254b614a721b3ee9c
package main
import "core:sys/windows"
import "core:strings"
import "core:fmt"
@oskarnp
oskarnp / bit_set_iterator.odin
Created February 11, 2024 08:29
bit_set_iterator.odin
package main
import "core:fmt"
import "base:intrinsics"
main :: proc() {
X :: enum { A, B, C }
Y :: bit_set[X];
values := Y{.A, .C};
@oskarnp
oskarnp / Odin.sublime-build
Last active May 9, 2024 17:11
Sublime build system for Odin
{
"selector":"source.odin",
"file_regex": "^(.+)\\(([0-9]+):([0-9]+)\\) (.+)$",
"shell_cmd":"odin check \"$file_path\" -no-entry-point",
"variants":[
//
// current file
//
// syntax check
@oskarnp
oskarnp / tracking_allocator.odin
Last active May 9, 2024 17:10
Odin tracking allocator
package main
import "core:fmt"
import "core:mem"
import "core:log"
import "core:runtime"
// NOTE(Oskar): An example of how to do a leak checking allocator with Odin's context system.
//
@oskarnp
oskarnp / logging_allocator.odin
Last active July 22, 2020 10:35
Odin Logging Allocator
import "core:fmt"
import "core:mem"
import "core:log"
Logging_Allocator_Data :: struct {
backing: mem.Allocator,
}
logging_allocator :: proc(data: ^Logging_Allocator_Data) -> mem.Allocator {
// `package log` uses context.temp_allocator and temp_allocator is lazily initialized. Dummy allocate here
package ratelimit
import "core:fmt"
import "core:time"
ratelimit :: proc(limit: time.Duration, loc := #caller_location) -> (ok: bool) {
@static state: map[u64]time.Time;
start, end := state[loc.hash], time.now();
ok = start._nsec == 0 || time.diff(start, end) > limit;
if ok do state[loc.hash] = end;
@oskarnp
oskarnp / range_example.odin
Last active July 22, 2020 10:36
Odin range example
package range_example
import "core:fmt"
main :: proc() {
fr := forward_range(0, 9);
for i in next_range(&fr) do fmt.printf("%v ", i);
fmt.printf("\n");
// output: 0 1 2 3 4 5 6 7 8 9
import "core:fmt"
import "core:strings"
main :: proc() {
// Demo: Split `text` on any character in delimiter string.
{
text := "\nThis is a long text\nwith line breaks.";
lines_itr := split_iterator(text, "\n");
for line in split_any_next(&lines_itr) {
fmt.println(string(line));