Skip to content

Instantly share code, notes, and snippets.

@vassvik
vassvik / main.c
Last active September 8, 2018 12:58
minimal glfw, C vs Odin
#include <stdio.h> // fprintf, stderr
#include <GLFW/glfw3.h>
// this function will be called internally by GLFW whenever an error occur.
void error_callback(int error, const char* description);
int main()
{
// tell GLFW to call error_callback if an internal error ever occur at some point inside GLFW functions.
@vassvik
vassvik / font_atlas_packing_stbtt_color.c
Last active September 8, 2018 13:27
Font atlas packing with stbtruetype.h, with optional colored visualization of packing
#define STB_RECT_PACK_IMPLEMENTATION
#include "stb_rect_pack.h" // For better packing overall
#define STB_TRUETYPE_IMPLEMENTATION
#include "stb_truetype.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h" // for saving png
/*
@vassvik
vassvik / acos.go
Last active September 8, 2018 13:26
Benchmarking acos implementation for input values around 1.0, comparing with libm's acos.
import "core:fmt.odin";
import "core:math.odin";
import "shared:odin-glfw/glfw.odin";
foreign_system_library m "m";
foreign m {
acos :: proc(x: f64) -> f64 #link_name "acos" ---;
}
@vassvik
vassvik / gist:0a08ce59b678a77579db9392df983306
Last active September 25, 2017 08:14
Odin vector types and bulk operations
// Vectors are similar to arrays, but they are allow for bulk operations to all of its elements.
// Thet are meant to map to hardware level vector instructions but they can be any arbitrary length.
// Vector types only allow numeric and logical types (integers, floats, complex numbers, booleans).
// A vector type is composed as: `[vector size]T`.
// Almost all operators that work on the base type also work on the vector type.
// Exceptions are comparisons for bool vectors, shifts are for integer vectors.
fmt.println("complex operations");
c1 := [vector 2]complex64{1.0 + 3.14i, 3.0 - 5.0i};
@vassvik
vassvik / file.go
Last active September 25, 2017 08:14
Odin polymoprhic procedures and parametric types
// Odin has support for explicit and implicit polymorphic procedures and parametric types
// An explicit polymorphic procedure has the type passed as a parameter,
// while an implicit polymorphic procedure infers the type from the arguments
// a typical use-case for an explicit polymorphic procedure can be found in core/_preload.odin:
new :: proc(T: type) -> ^T {
ptr := cast(^T)alloc(size_of(T), align_of(T));
ptr^ = T{};
return ptr;
}
@vassvik
vassvik / file.go
Created September 25, 2017 00:41
`using` in Odin
// Odin has a powerful keyword called `using`,
// which is similar to the `using` keyword in other languages like C++,
// but also a lot more versatile and powerful in Odin.
// The simplest case, that is similar to C++'s usage: it makes the names of an import name visible
// in function scope. Be careful, as this might call name collision.
fmt.println("This is a new line");
using fmt;
println("This is a new line, without fmt.");
@vassvik
vassvik / events.go
Created September 29, 2017 17:39
An event queue backed by a ring buffer and tagged unions implemented in Odin. (Note: File names are .go for syntax highlighting)
import "core:fmt.odin";
// Define event types, based on GLFW's events
Window_Iconify_Event :: struct { iconified: i32};
Window_Refresh_Event :: struct { };
Window_Focus_Event :: struct { focused: i32 };
Window_Close_Event :: struct { };
Window_Size_Event :: struct { width, height: i32 };
Window_Pos_Event :: struct { xpos, ypos: i32 };
@vassvik
vassvik / Remote OpenGL Setup.md
Created November 6, 2017 11:35 — forked from shehzan10/Remote OpenGL Setup.md
Remote OpenGL Without Display

Remote OpenGL Setup without X

A full OpenGL profile requires X to be running. For X to run, it requires a display to be connected to the machine. Given that most server machines do not have this, it becomes difficult to run OpenGL.

This document details how to get OpenGL and X up and running without having a display connected to the sevrer.

Requirements

You will need access to the remote system over SSH. To run the tool, you will need libGL.so and libX11.so. These are installed when X and the NVIDIA Drivers are installed. So there is nothing special required to install these.

Another tool I would recommend strongly is glewinfo. Most linux distributions ship this with the glew-utils package. An alternate to glewinfo is glxinfo which is present on all systems with X. You can substitute glewinfo with glxinfo in all the commands below if needed.

@vassvik
vassvik / make_font_bitmap.c
Last active March 23, 2024 10:08
Font atlas packer with stbtruetype.h
#include <stdio.h>
#define STB_RECT_PACK_IMPLEMENTATION
#include <stb/stb_rect_pack.h> // optional, used for better bitmap packing
#define STB_TRUETYPE_IMPLEMENTATION
#include <stb/stb_truetype.h>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb/stb_image_write.h>
@vassvik
vassvik / obj_loader.go
Last active September 8, 2018 13:12
a simple Wavefront OBJ loader in Odin
import "core:os.odin";
import "core:fmt.odin";
import "core:strconv.odin";
Vec2 :: [2]f32;
Vec3 :: [3]f32;
Model_Data :: struct {
vertex_positions: []Vec3,
vertex_normals: []Vec3,