Skip to content

Instantly share code, notes, and snippets.

@fp64
fp64 / viewobj.cpp
Last active October 24, 2026 11:23
Self-contained Wavefront OBJ mesh viewer (no materials) for Windows and Linux (or anything that has SDL2), using softrender.
// Public Domain under http://unlicense.org, see link for details.
// Self-reference: https://gist.github.com/fp64/55b778b310f00aa4ca1304d8fd99a377
// Self-contained Wavefront OBJ viewer for Windows and Linux
// (or anything that has SDL2), using softrender. Fairly limited:
// no materials/textures, no points/lines/curves/NURBS, no
// smoothing groups. Not fast, but should be usable up to
// about 500k triangles.
// Usage: viewobj [--fullscreen] [--size=WIDTHxHEIGHT] FILE
@fp64
fp64 / example_sdl2_softrender.cpp
Last active October 28, 2026 07:18
Softrender backend for Dear ImGui, as well as examples for SDL2 and WinAPI.
// Dear ImGui: standalone example application for SDL2 + Softrender
// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.)
// Learn about Dear ImGui:
// - FAQ https://dearimgui.com/faq
// - Getting Started https://dearimgui.com/getting-started
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
// - Introduction, links and more at the top of imgui.cpp
// See imgui_impl_sdl2.cpp for details.
@fp64
fp64 / indeint.c
Last active October 29, 2026 14:33
In-place (de)interleave array of size 2*n, in O(n) time and O(1) extra space.
/* Public Domain under http://unlicense.org, see link for details. */
/* Self-reference: https://gist.github.com/fp64/d54bfa1070bfd8f3e845018de7b0bf7d */
/*
In-place (de)interleave array of size 2*n, in O(n) time and O(1) extra space.
The "interleave" operation on an array produces an array of
alternating elements from its lower and higher halves:
a[0],...,a[2*n-1] -> a[0],a[n],a[1],a[n+1],...,a[n-1],a[2*n-1]
@fp64
fp64 / mb3d.h
Created September 28, 2026 18:24
Simplistic code for calculating 3D metaballs.
/* Public Domain under http://unlicense.org, see link for details. */
/*
mb3d.h - a simple single-file library for 3D metaballs.
USAGE
This file acts as its own header. To instantiate
an implementation do
#define MB3D_IMPLEMENTATION
in ONE translation unit that includes this file.
@fp64
fp64 / utf8.c
Created September 22, 2026 12:42
Short, ugly and slow UTF-8 parsing routune. Public domain.
// Public Domain under http://unlicense.org, see link for details.
// Short, ugly and slow UTF-8 parsing routune.
// Exhaustively verified on all 0..4 byte strings
// against https://bjoern.hoehrmann.de/utf-8/decoder/dfa/
// (which is what you may want to actually use).
#include <stdint.h>
// Returns the initial codepoint in UTF-8 string [b;e),
@fp64
fp64 / blend.c
Created September 22, 2026 09:30
Portable scalar functions for blending RGBA pixels represented as uint32, in both "lerp" and "premultiplied alpha" modes.
// Public Domain under http://unlicense.org, see link for details.
// Portable scalar functions for blending RGBA pixels
// represented as uint32, in both "lerp" and
// "premultiplied alpha" modes, extracted from
// https://github.com/fp64/dbc_blit
// (see dbcB_bla_1_c and dbcB_blp_1_c). For
// discussion about premultiplied alpha, see e.g.
// https://tomforsyth1000.github.io/blog.wiki.html#[[Premultiplied%20alpha]]
// https://tomforsyth1000.github.io/blog.wiki.html#[[Premultiplied%20alpha%20part%202]]
@fp64
fp64 / bdf2c.py
Created September 5, 2026 12:37
A simple utility to convert .bdf font files to C code. Doesn't do much any validation, and expects "sensible" .bdf input. Some BDF fonts may be found e.g. at https://font.gohu.org/ (WTFPL) or https://github.com/IT-Studio-Rech/bdf-fonts (mostly public domain) or https://github.com/stgiga/UnifontEX/ (GPL2 with font embedding exception).
#!/usr/bin/python3
# Public Domain under http://unlicense.org, see link for details.
# A simple utility to convert .bdf font files to C code.
# Doesn't do much any validation, and expects "sensible" .bdf input.
import sys
import optparse
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
@fp64
fp64 / keymap.h
Created December 24, 2025 02:23
Quick-and-dirty conversion between VK_* and SDLK_* keycodes.
// Public Domain under http://unlicense.org, see link for details.
// Quick-and-dirty conversion between VK_* and SDLK_* keycodes.
// Rudimentary, and generally assumes US ANSI keyboard.
static long vk2sdlk(long key)
{
static const long S=1L<<30,lut[256]={
0, 0, 0,S|155, 0, 0, 0, 0, 8, 9, 0, 0,S|156, 13, 0, 0,
0, 0, 0,S| 72,S| 57, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0,S| 1,
Move-optimal solutions to "auto-generated" sokoban level set
(Yoshio Murase, https://www.ne.jp/asahi/ai/yoshio/sokoban/auto52/index.html)
soko001.txt luuluRurrrddlLrruullldlddrdrrUdlluluururrrddLddlluUddrruuLUdrddlluluuRuRDllddrUddrruuL
soko002.txt lllddddrUluuurrddLdlUrruurrddLdLUlldRurrruullllDDrrUdlluurRddlddlUUrrrdLullddrUruuullDDRdrUrruuL
soko003.txt lDLddddlUruuurrdLulDlluRRdDDlUruulldRurDrruL
soko004.txt ldLruulDLDRRdrUUUlldldlddrUUlUUdRRRdrU
soko005.txt ldDurrdLdLLdlluurDDrurruulDrdLLddrUUldlluurDldRurrruulDrdLLLdlUrrrdLL
soko006.txt uluurDrrrrddLLUdrruulLLulldRlddrUUluRdddRRuuLrddlluUrrrrddL
soko007.txt dlluluuRDDlddrruruuLrruullDlDRllddRUluurrdRdrUUdlddLdlU