Skip to content

Instantly share code, notes, and snippets.

View karl-zylinski's full-sized avatar

Karl Zylinski karl-zylinski

View GitHub Profile
// A small test program of me trying Odin + Box2D + Raylib
// Made during this stream: https://www.youtube.com/watch?v=LYW7jdwEnaI
// I used these bindings https://github.com/cr1sth0fer/odin-box2d download them and put them in a sub-folder "box2d" next to this file.
// Then you can build using `odin run .`
package game
import b2 "box2d"
import rl "vendor:raylib"
@karl-zylinski
karl-zylinski / load_ttf_from_memory_premultiply_alpha.odin
Created April 15, 2024 11:28
Loading a TTF in Odin and multiply alpha into the gray component of the gray+alpha atlas
load_ttf_from_memory :: proc(file_data: []byte, font_size: int) -> rl.Font {
font := rl.Font {
baseSize = i32(font_size),
glyphCount = 95,
}
font.glyphs = rl.LoadFontData(&file_data[0], i32(len(file_data)), font.baseSize, {}, font.glyphCount, .DEFAULT)
if font.glyphs != nil {
font.glyphPadding = 4
@karl-zylinski
karl-zylinski / tracking_alloc_example.odin
Created March 3, 2024 20:26
Example of how to setup tracking allocator
// from https://odin-lang.org/docs/overview/#when-statements, see end of that section
package main
import "core:fmt"
import "core:mem"
main :: proc() {
when ODIN_DEBUG {
track: mem.Tracking_Allocator
package assets_builder
import "core:fmt"
import "core:os"
import "core:strings"
import "core:path/slashpath"
import "core:hash"
dir_path_to_file_infos :: proc(path: string) -> []os.File_Info {
d, derr := os.open(path, os.O_RDONLY)
{
"selector": "source.odin",
"file_regex": "^(.+)\\(([0-9]+):([0-9]+)\\) (.+)$",
"file_patterns": ["*.odin"],
"cmd": ["build.bat"],
"working_dir": "c:/repos/cat-game",
"variants": [
{
"name": "run",
"cmd": "build.bat && start run.bat",
[EditorTool("Tile Placer Tool", typeof(TileData))]
class TilePlacerTool : EditorTool
{
private GUIContent m_iconContent;
void OnEnable()
{
var icon = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/Textures/Editor/TileEditorIcon.png");
// Icon for tools toolbar
@karl-zylinski
karl-zylinski / d3d12_triangle.odin
Last active October 23, 2023 08:00
D3D12 triangle in Odin
// D3D12 single-function triangle sample.
// Contributors: Karl Zylinski <karl@zylinski.se>
// Based on: https://github.com/rdunnington/d3d12-hello-triangle/blob/master/main.c
package d3d12_triangle
import "core:fmt"
import "core:mem"
import "core:sys/windows"
import "core:os"
# Linearly propagates the error of a velocity given in celestial coordinates to cartesian via the
# formulas identical to the ones in function cartesian_velocity_from_celestial.
def celestial_coords_to_cartesian_error(
ra, dec, r,
ra_error, dec_error, r_error,
pmra, pmdec, rv,
pmra_error, pmdec_error, rv_error):
dvx_dra = -cos(dec)*sin(ra)*rv + r*cos(dec)*cos(ra)*pmra - r*sin(dec)*sin(ra)*pmdec
dvx_ddec = -sin(dec)*cos(ra)*rv - r*sin(dec)*sin(ra)*pmra + r*cos(dec)*cos(ra)*pmdec
dvx_dr = cos(dec)*sin(ra)*pmra + sin(dec)*cos(ra)*pmdec
# propagates error of |v2 - v1| where v2 and v1 are vectors and parameters are in celestial coordinates
def celestial_magnitude_of_velocity_difference_error(
ra1_deg, dec1_deg, r1,
ra1_error_deg, dec1_error_deg, r1_error,
pmra1_deg_per_s, pmdec1_deg_per_s, rv1,
pmra1_error_deg_per_s, pmdec1_error_deg_per_s, rv1_error,
ra2_deg, dec2_deg, r2,
ra2_error_deg, dec2_error_deg, r2_error,
pmra2_deg_per_s, pmdec2_deg_per_s, rv2,
pmra2_error_deg_per_s, pmdec2_error_deg_per_s, rv2_error):
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
struct Color
{
unsigned char r, g, b;
};