Skip to content

Instantly share code, notes, and snippets.

View mmozeiko's full-sized avatar

Mārtiņš Možeiko mmozeiko

View GitHub Profile
@mmozeiko
mmozeiko / !README.md
Last active April 25, 2024 19:03
Download MSVC compiler/linker & Windows SDK without installing full Visual Studio

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 portable-msvc.py 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 portable-msvc.py --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
mmozeiko / win32_d3d11.c
Last active April 14, 2024 21:46
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 / dwrite.cpp
Created July 25, 2018 17:36
DirectWrite without D2D
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <dwrite.h>
#include <intrin.h>
#pragma comment (lib, "gdi32.lib")
#pragma comment (lib, "user32.lib")
#pragma comment (lib, "dwrite.lib")
#define CHECK(x) do { if (!(x)) __debugbreak(); } while (0)
@mmozeiko
mmozeiko / webcam_capture.c
Created August 28, 2019 20:25
Capture webcam device with Media Foundation API
#define COBJMACROS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <mfapi.h>
#include <mfidl.h>
#include <mfreadwrite.h>
#include <stdio.h>
#include <intrin.h>
@mmozeiko
mmozeiko / win32_opengl.c
Last active April 6, 2024 03:02
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 / armv8_tsc.h
Last active April 2, 2024 08:34
armv8 timer & cycle counter
#pragma once
#define _GNU_SOURCE
#include <stdint.h>
#include <stdbool.h>
#include <sched.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/perf_event.h>
@mmozeiko
mmozeiko / unitypackage2zip.py
Created February 9, 2019 12:31
Python script that converts .unitypackage file to .zip archive
#!/usr/bin/env python3
import sys
import tarfile
import zipfile
from pathlib import Path
src = sys.argv[1]
dst = Path(src).name + ".zip"
@mmozeiko
mmozeiko / build.cmd
Last active March 27, 2024 04:20
download & build llvm+clang on Windows
@echo off
setlocal enabledelayedexpansion
rem !!! build requirements !!!
rem Visual Studio 2022 - https://visualstudio.microsoft.com/vs/
rem 7-Zip - https://www.7-zip.org/download.html
rem Python - https://www.python.org/downloads/
rem CMake - http://www.cmake.org/download/
rem ninja.exe - https://github.com/ninja-build/ninja/releases/latest
@mmozeiko
mmozeiko / tls_client.c
Last active March 26, 2024 02:27
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>