Skip to content

Instantly share code, notes, and snippets.

View ciano1000's full-sized avatar

Cian Mc Sweeney ciano1000

  • Galway, Ireland.
View GitHub Profile
// Gradual-commit arena demonstration
// This is free and unencumbered software released into the public domain.
#include <stddef.h>
#include <string.h>
static void *os_reserve(ptrdiff_t);
static _Bool os_commit(void *, ptrdiff_t);
#define ARENA_PAGESIZE ((ptrdiff_t)1<<26)
@mmozeiko
mmozeiko / tls_client.c
Last active March 21, 2025 15:58
simple example of TLS socket client using win32 schannel api
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <windows.h>
#define SECURITY_WIN32
#include <security.h>
#include <schannel.h>
#include <shlwapi.h>
#include <assert.h>
#include <stdio.h>
@mmozeiko
mmozeiko / shader.hlsl
Last active November 7, 2024 20:23
compute shader for rendering monospaced glyphs in grid
//
struct TerminalCell
{
// cell index into GlyphTexture, should be two 16-bit (x,y) values packed: "x | (y << 16)"
uint GlyphIndex;
// 0xAABBGGRR encoded colors, nonzero alpha for Foreground indicates to render colored-glyph
// which means use RGB values from GlyphTexture directly as output, not as ClearType blending weights
uint Foreground;
@mmozeiko
mmozeiko / win32_d3d11.c
Last active April 20, 2025 08:17
setting up and using D3D11 in C
// example how to set up D3D11 rendering on Windows in C
#define COBJMACROS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <d3d11.h>
#include <dxgi1_3.h>
#include <d3dcompiler.h>
#include <dxgidebug.h>
@mmozeiko
mmozeiko / win32_opengl.c
Last active February 26, 2025 12:38
setting up and using modern OpenGL 4.5 core context on Windows
// example how to set up OpenGL core context on Windows
// and use basic functionality of OpenGL 4.5 version
// important extension functionality used here:
// (4.3) KHR_debug: https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_debug.txt
// (4.5) ARB_direct_state_access: https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_direct_state_access.txt
// (4.1) ARB_separate_shader_objects: https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_separate_shader_objects.txt
// (4.2) ARB_shading_language_420pack: https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_shading_language_420pack.txt
// (4.3) ARB_explicit_uniform_location: https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_explicit_uniform_location.txt
@mmozeiko
mmozeiko / d3d11_pixels.c
Last active November 22, 2024 03:04
drawing pixels in software & showing them to window by uploading via D3D11
#define COBJMACROS
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <d3d11.h>
#include <stdint.h>
#include <string.h>
#include <intrin.h>
@mmozeiko
mmozeiko / write_bmp.c
Created September 23, 2020 00:57
saving simple 32-bit RGBA top-down bmp file
#include <stdarg.h>
#include <stdio.h>
static void write(FILE* f, const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
char ch;
while ((ch = *fmt++))
{
@judah-caruso
judah-caruso / theme-definitions.4coder
Last active February 3, 2023 03:15
A file containing 4coder theme definitions and their descriptions
// This file contains each 4coder theme definition and what it does within the editor.
// Main editor
defcolor_back = 0xFF000000; // Main buffer background
defcolor_text_default = 0xFFFFFFFF; // Default character foreground
defcolor_at_cursor = 0xFF000000; // Cursor foreground
defcolor_cursor = {0xFF000000, 0xFF000000}; // [0] Cursor background, [1] Active macro recording cursor background
defcolor_mark = 0xFF000000; // Mark background
defcolor_highlight_cursor_line = 0xFF000000; // Current line background
defcolor_margin_active = 0xFF000000; // Active buffer outline
@mmozeiko
mmozeiko / xbox_test.c
Last active October 13, 2024 00:45
Getting xbox controller input without xinput
// cl.exe xbox_test.c /link setupapi.lib user32.lib
#include <windows.h>
#include <setupapi.h>
#include <dbt.h>
#include <stdio.h>
/// interface
#define XBOX_MAX_CONTROLLERS 16
@mmozeiko
mmozeiko / capture_desktop_dxgi_gl.c
Last active October 13, 2024 00:45
Capture desktop with IDXGIOutputDuplication and use as OpenGL texture
//
// First download glcorearb.h, wglext.h and platform.h files
// Then compile: cl.exe capture_desktop_dxgi_gl.c /I. d3d11.lib dxgi.lib dxguid.lib gdi32.lib opengl32.lib user32.lib dwmapi.lib
//
#define COBJMACROS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <d3d11.h>