Skip to content

Instantly share code, notes, and snippets.

View thebirk's full-sized avatar

Aleksander Birkeland thebirk

View GitHub Profile
// Release - x64
void set_background_color(float r, float g, float b);
void draw_line(float x0, float y0, float x1, float y1, float r, float g, float b, float a);
float print_string(char* text, float x, float y, float size, float r, float g, float b, float a);
float print_int(int number, float x, float y, float size, float r, float g, float b, float a);
float print_float(float number, int decimals, float x, float y, float size, float r, float g, float b, float a);
double math_cos(double x);
double math_sin(double x);
double math_atan2(double x, double y);
TypeUniformMapping :: struct {
typetype: typeid,
set_uniform: proc(loc: i32, value: rawptr),
}
type_to_uniform_map := map[gl.Uniform_Type]TypeUniformMapping{
// If we map typeid to Uniform_Type, we could support stuff like array of floats and vec3s
gl.Uniform_Type.FLOAT = {typeid_of(f32), proc(loc: i32, value: rawptr) {
gl.Uniform1f(loc, (cast(^f32)value)^);
@thebirk
thebirk / annotations.go
Last active February 7, 2019 16:44
Odin annotations proposal
// This example has some faults, the most important one is how are you gonna know what data
// the annotation actually annotates. The best way would probably be to tag it with
// {entity_id: typeid, entity_ptr: rawptr}, this would allow you to switch on the type
// and cast the ptr. That way you can ensure the annotation was added to the correct type
// and not some random entity
package main
// Proposed change for existing compiler attributes
Go src: https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/nbody-go-3.html
Odin src: https://gist.github.com/thebirk/e02df1b94ef07fb62b50d64ba2f5328e
$ go build
$ timemem gotest.exe 50000000
-0.169075164
-0.169059907
Exit code : 0
Elapsed time : 3.76
Kernel time : 0.00 (0.0%)
package main
import "core:fmt";
import "core:math";
FloatType :: f64;
Vec3 :: distinct [3]FloatType;
Body :: struct {
pos: Vec3,
@thebirk
thebirk / huffman.go
Last active November 9, 2018 08:08
Basic huffman tree in Odin
package huffman
import "core:fmt"
import "core:strings"
import "core:mem"
import "core:math"
using import "arraylist"
HuffmanNode :: struct {
freq: int,
@thebirk
thebirk / arraylist.go
Created November 9, 2018 07:51
Polymorphic ArrayList - Odin
package arraylist
import "core:mem"
ArrayList :: struct(T: typeid) {
data: []T,
size: int,
allocator: mem.Allocator,
}
package bed
using import "core:c"
import "core:os"
//foreign import ftlib "freetype271.lib";
when os.OS == "windows" do foreign import ftlib "freetype.lib";
else when os.OS == "linux" do foreign import ftlib "system:freetype";
else {
#assert(false);
package bed
using import "core:c"
import "core:os"
//foreign import ftlib "freetype271.lib";
when os.OS == "windows" do foreign import ftlib "freetype271.lib";
else {
#assert(false);
}
#include <SDL2/SDL_image.h>
SDL_Texture *fontTexture = 0;
const char *layout =
"ABCDEFGHIJKLMNOP"
"QRSTUVWXYZ!?. "
"1234567890"
;
void initText() {