Skip to content

Instantly share code, notes, and snippets.


Mārtiņš Možeiko mmozeiko

  • Epic Games / RAD Game Tools
  • Kirkland, WA
  • Twitter @mmozeiko
View GitHub Profile
mmozeiko / !
Last active Jan 31, 2023
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 Oct 12, 2022
flush file cache on Windows
View FlushFileCache.c
// clang.exe -Os -fno-unwind-tables -nostdlib -fuse-ld=lld -Wl,-fixed,-merge:.rdata=.text,-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 Jan 10, 2022
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 Jan 26, 2023
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 Jan 4, 2023
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 Aug 23, 2021
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 Dec 27, 2022
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;
mmozeiko / shader.hlsl
Last active Dec 12, 2022
compute shader for rendering monospaced glyphs in grid
View shader.hlsl
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 / image2clipboard.c
Last active Oct 12, 2022
example how to put RGBA image in clipboard
View image2clipboard.c
#include "stb_image.h" // get from
#include <windows.h>
int main(int argc, char* argv[])
int w, h;
stbi_uc* data = stbi_load(argv[1], &w, &h, NULL, 4);
mmozeiko / x11_opengl.c
Last active Dec 1, 2022
setting up and using modern OpenGL 4.5 core context on X11 with EGL
View x11_opengl.c
// example how to set up OpenGL core context on X11 with EGL
// and use basic functionality of OpenGL 4.5 version
// to compile on Ubuntu first install following packages: build-essential libx11-dev libgl-dev libegl-dev, then run:
// gcc x11_opengl.c -o x11_opengl -lm -lX11 -lEGL
// important extension functionality used here:
// (4.3) KHR_debug:
// (4.5) ARB_direct_state_access:
// (4.1) ARB_separate_shader_objects: