Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / circular_buffer.go
Last active September 8, 2018 13:07
Simple circular buffer in Odin
Circular_Buffer :: struct(T: type, N: int) {
data: [N]T,
cursor: int,
length: int,
}
push_back :: inline proc(using cb: ^$T/Circular_Buffer, v: T.T) -> bool #no_bounds_check {
data[(cursor + length) %% T.N] = v;
if length < T.N {
@vassvik
vassvik / main.c
Last active September 8, 2018 13:08
Minimal GLFW example in C
// compile with one of the following, probably.
//
// in linux:
// if glfw is built as a dynamic lib:
// gcc main.c -lglfw
// gcc main.c -lglfw3
//
// or, if glfw is built as a static lib:
// gcc main.c -lglfw -lX11 -lXxf86vm -lpthread -lXrandr -lXinerama -lXcursor -lXi
// gcc main.c -lglfw3 -lX11 -lXxf86vm -lpthread -lXrandr -lXinerama -lXcursor -lXi
@vassvik
vassvik / quaternions.cpp
Last active September 8, 2018 13:09
Testing quaternion rotation equivalencies
#include <stdio.h>
#include <math.h>
struct vec3 {
float x, y, z;
vec3(float x, float y, float z) : x(x), y(y), z(z) {}
vec3(float x) : x(x), y(x), z(x) {}
};
@vassvik
vassvik / vs_parameters.txt
Last active September 8, 2018 13:12
Default Visual Studio compiler parameters and what they mean
/permissive- standards conformance
/MP build with multiple processors
/GS buffer security check
/Qpar auto-parallelizer
/GL whole program optimization
/W3 warning level
/wd"4305" identifier' : truncation from 'type1' to 'type2'
/Gy enable function-level linking
/Zc:wchar_t wchar_t is native type
/Zi debug information format