Skip to content

Instantly share code, notes, and snippets.

View karl-zylinski's full-sized avatar

Karl Zylinski karl-zylinski

View GitHub Profile
@karl-zylinski
karl-zylinski / odin_raylib_basic.odin
Last active March 8, 2025 15:53
For getting started with Odin + Raylib
/*
This is a minimal Odin + Raylib example.
Put this file in an empty folder, navigate to that folder using a teriminal
and then run this command:
odin run .
To see all the things available in Raylib, open `raylib.odin` and look around.
You'll find it here:
<odin_install_directory>/vendor/raylib/raylib.odin
@karl-zylinski
karl-zylinski / raylib_minimal.odin
Last active December 28, 2024 03:07
Minimal Odin + Raylib example.
// Minimal Odin + Raylib example that opens window and lets you control a
// rectangle using the arrow keys. Beginners can use this as a starting point.
//
// Copy this into a file called whatever_you_want.odin inside an empty folder.
// Use the command prompt to navigate to that folder and run:
// odin run .
// Note the period, with a space before it! This should run this minimal example.
package raylib_minimal
import rl "vendor:raylib"
@karl-zylinski
karl-zylinski / odin_book_table_of_contents.txt
Last active January 11, 2025 17:12
Upcoming Odin book table of contents
1: Introduction
1.1: Why learn Odin?
1.2: Overview
1.3: Installing the Odin compiler
1.4: If you get stuck
1.5: Let's go!
2: Hellope! A tiny program
2.1: Compile and run the code
2.2: Line-by-line
@karl-zylinski
karl-zylinski / peek_at_next_rune.odin
Last active October 1, 2024 20:41
Example of how to look at next rune when iterating a string
package runefun
import fmt "core:fmt"
import "core:unicode/utf8"
main :: proc() {
str := "小猫咪"
// i is the byte index
for r, i in str {
@karl-zylinski
karl-zylinski / open_win32_window.odin
Last active September 3, 2024 22:25
Open a window using Windows API in Odin
package open_win32_window
import win "core:sys/windows"
main :: proc() {
instance := win.HINSTANCE(win.GetModuleHandleW(nil))
assert(instance != nil, "Failed to fetch current instance")
class_name := win.L("Windows Window")
cls := win.WNDCLASSW {
// extra things I add to hot reload script to make auto reload work
odin build file_version_builder
IF %ERRORLEVEL% NEQ 0 exit /b 1
file_version_builder.exe
IF %ERRORLEVEL% NEQ 0 exit /b 1
@karl-zylinski
karl-zylinski / rect_cut.odin
Last active April 22, 2025 09:29
For splitting up rectangles into smaller rectangles easily. Great for IMGUI layouting.
Rect :: struct {
x: f32,
y: f32,
width: f32,
height: f32,
}
cut_rect_top :: proc(r: ^Rect, y: f32, m: f32) -> Rect {
res := r^
res.y += m
@karl-zylinski
karl-zylinski / refresh_padded_tileset.odin
Created June 28, 2024 14:30
Takes a tileset and generates a new one with 1 px padding around all the tiles. The pixel at the border of the tile is copied to that border. This fixes subpixel camera interpolation glitches.
refresh_padded_tileset :: proc() {
if g_mem.tileset_padded.id != 0 {
rl.UnloadTexture(g_mem.tileset_padded)
g_mem.tileset_padded = {}
}
ts_source := load_image(.Tileset)
defer rl.UnloadImage(ts_source)
tileset_height := ts_source.height / TileHeight
{
"folders":
[
{
"path": ".",
},
],
"build_systems":
[
{
package game
import rl "vendor:raylib"
import "core:mem"
import "core:fmt"
import "core:encoding/json"
import "core:os"
Animation_Name :: enum {
Idle,