Skip to content

Instantly share code, notes, and snippets.

View mmozeiko's full-sized avatar

Mārtiņš Možeiko mmozeiko

  • Epic Games / RAD Game Tools
  • WA
  • Twitter @mmozeiko
View GitHub Profile
mmozeiko / preview.c
Last active October 7, 2023 20:47
windows shell preview handler example
View preview.c
// example of using Windows Preview Handler
#include <windows.h>
#include <shlwapi.h>
#include <shellapi.h>
#include <shobjidl.h>
mmozeiko / win32_webgpu.c
Last active November 12, 2023 16:38
setting up and using WebGPU in C using Dawn
View win32_webgpu.c
// example how to set up WebGPU rendering on Windows in C
// uses Dawn implementation of WebGPU:
// download pre-built Dawn webgpu.h/dll/lib files from
#include "webgpu.h"
#include <windows.h>
mmozeiko / upng.h
Last active November 3, 2023 18:29
uncompressed png writer & reader
View upng.h
#pragma once
// uncompressed png writer & reader
// supports only 8-bit and 16-bit formats
// Performance comparison for 8192x8192 BGRA8 image (256MB)
// Compiled with "clang -O2", AVX2 requires extra "-mavx2" or "/arch:AVX2" argument
// For libpng (compressed) uses default libpng/zlib compression settings
// For libpng (uncompressed) case following two functions are used:
mmozeiko / !
Last active November 28, 2023 19:04
Download MSVC compiler/linker & Windows SDK without installing full Visual Studio
View !

This downloads standalone 64-bit MSVC compiler, linker & other tools, also headers/libraries from Windows SDK into portable folder, without installing Visual Studio. Has bare minimum components - no UWP/Store/WindowsRT stuff, just files & tools for 64-bit native desktop app development.

Run python.exe and it will download output into msvc folder. By default it will download latest available MSVC & Windows SDK - currently v14.32.17.2 and v10.0.22621.0.

You can list available versions with python.exe --show-versions and then pass versions you want with --msvc-version and --sdk-version arguments.

To use cl.exe/link.exe from output folder, first run setup.bat - after that PATH/INCLUDE/LIB env variables will be setup to use all the tools as usual. You can also use clang-cl.exe with these includes & libraries.

To use clang-cl.exe without running setup.bat, pass extra /winsysroot msvc argument (msvc is folder name where output is stored).

mmozeiko / FlushFileCache.c
Last active June 26, 2023 03:08
flush file cache on Windows
View FlushFileCache.c
// clang.exe -Os -nostdlib -fuse-ld=lld -Wl,-fixed,-subsystem:console FlushFileCache.c -o FlushFileCache.exe
#include <windows.h>
#pragma comment (lib, "kernel32.lib")
#pragma comment (lib, "advapi32.lib")
#define error(str) do { DWORD written; WriteFile(GetStdHandle(STD_ERROR_HANDLE), str, sizeof(str)-1, &written, NULL); } while (0)
mmozeiko /
Created January 10, 2022 02:24
packs multiple images into ico file
#!/usr/bin/env python3
# packs multiple images (bmp/png/...) into ico file
# width and height of images must be <= 256
# pixel format of images must be 32-bit RGBA
import argparse
import struct
import os
from PIL import Image #
mmozeiko / tls_client.c
Last active November 10, 2023 03:01
simple example of TLS socket client using win32 schannel api
View tls_client.c
#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 / win32_opengl_multi.c
Last active January 4, 2023 19:44
setting up modern OpenGL 4.5 context for drawing to multiple windows
View win32_opengl_multi.c
// example how to set up OpenGL core context on Windows for rendering to multiple windows
#define WINDOW_COUNT 4 // how many windows we'll be opening?
// important extension functionality used here:
// (4.3) KHR_debug:
// (4.5) ARB_direct_state_access:
// (4.1) ARB_separate_shader_objects:
// (4.2) ARB_shading_language_420pack:
// (4.3) ARB_explicit_uniform_location:
mmozeiko / q1.c
Created August 23, 2021 00:35
Quake 1 animated model rendering
View q1.c
// download glfw3 from and then compile:
// cl.exe -O2 q1.c -Iinclude -link opengl32.lib glu32.lib lib-vc2019\glfw3dll.lib
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
mmozeiko / pcg32.h
Last active August 18, 2023 13:51
simple standalone C headers for PCG random number generator
View pcg32.h
#pragma once
#include <stdint.h>
#define PCG_DEFAULT_MULTIPLIER_64 6364136223846793005ULL
#define PCG_DEFAULT_INCREMENT_64 1442695040888963407ULL
typedef struct {
uint64_t state;
} pcg32;