Skip to content

Instantly share code, notes, and snippets.

View stillwwater's full-sized avatar

Lucas stillwwater

  • Microsoft
  • Canada
View GitHub Profile
@stillwwater
stillwwater / fgd.c
Last active November 6, 2025 05:45
Valve FGD Parser
#include "fgd.h"
enum {
TOK_EMPTY,
TOK_WORD,
TOK_INTEGER,
TOK_FLOAT,
TOK_STRING,
TOK_EOF,
};
@stillwwater
stillwwater / dsp.c
Last active November 27, 2025 04:27
IR convolution (for reverbs)
#define dsp_rfft_size(fftsize) ((fftsize) / 2 + 8)
#define dsp_overlap_size(fftsize) ((fftsize) / 2)
#define dsp_complex_array_count(fftsize) ((fftsize) * 2)
enum {
FFT_MIN_SIZE = 16,
FFT_MAX_SIZE = 4096,
};
struct fir_filter {
@stillwwater
stillwwater / wasapi_audio.c
Last active September 28, 2025 04:22
WASAPI playback sample
#include "module.h"
#define COBJMACROS
#include <windows.h>
#include <mmdeviceapi.h>
#include <audioclient.h>
struct audio_buffer audio_buffer;
struct audio_device audio_device;
#include "array.h"
// arenasize:
// virtual address size of the backing arenai
void *
make_array(usize arenasize, usize elementsize, char *name)
{
struct arena *arena = make_arena(arenasize, name);
struct array_header *array = arena_alloc_align(arena, 16, sizeof *array);
@stillwwater
stillwwater / rasterizer.asm
Last active November 11, 2024 19:28
Simple rasterizer
bits 64
default rel
%define R_PITCH (160 * 4)
%define R_PITCH_SHIFT 10
section .data
float_1 dd 1.0
align 32
@stillwwater
stillwwater / vid_win32.c
Created October 24, 2024 04:33
OpenGL on DXGI swapchain
#define COBJMACROS
#include <windows.h>
#include <d3d11.h>
#include <dxgi1_3.h>
cvar_t vid_dxgi = {"vid_dxgi", 0, CVAR_BOOL | CVAR_ALLOW | CVAR_INIT}; // DXGI layer for OpenGL
cvar_t vid_waitsync = {"vid_waitsync", 0, CVAR_BOOL | CVAR_ALLOW}; // lower latency, lower framerate
cvar_t vid_display = {"vid_display", -1, CVAR_INT | CVAR_ALLOW}; // -1 = primary
cvar_t vid_fullscreen = {"vid_fullscreen", 1, CVAR_BOOL | CVAR_ALLOW};
struct arena {
usize commitsize;
char *name;
char *start; // start of reserved address space
char *end; // end of reserved address space
char *heap; // start of user block
char *allocated; // end of allocated block
char *commited; // end of commited block
};
@stillwwater
stillwwater / gl_init.cpp
Created November 17, 2023 04:44
Create a modern OpenGL context on Windows
// Initializes an OpenGL device context for a given window.
void
gl_create_context(HWND hwnd)
{
HDC hdc;
HGLRC hglrc;
int pfd_index;
PIXELFORMATDESCRIPTOR pfd, device_pfd;
@stillwwater
stillwwater / gjk.c
Last active September 2, 2023 22:27
#include "core/vector.h"
#include "core/math.h"
#include "physics/clip.h"
struct phys_world {
unsigned static_clips_count;
struct aabb static_clips[PHYS_MAX_CLIP];
};
static struct phys_world phys;
spacing=1
id=1
nodes={}
rects={}
parent=nil
child=nil
function setpos(node)
local d=0
local p=node.p