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 / win32_d3d11.c
Last active March 1, 2025 20:49
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 / build-mesa3d.md
Last active May 9, 2024 15:20
builds statically linked mesa opengl32.dll with llvmpipe using Visual Studio (make sure to download mesa.patch file too!!!)
@mmozeiko
mmozeiko / build.cmd
Last active January 30, 2025 18:28
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 / etw_createfile.c
Last active October 12, 2024 23:26
Monitor which files are accessed with ETW
// this code will work only when compiled as 64-bit code, and on Windows 10
// older Windows version might require different structure definitions
#define NOMINMAX
#define INITGUID
#include <windows.h>
#include <evntrace.h>
#include <evntcons.h>
#pragma comment (lib, "shell32.lib")
@mmozeiko
mmozeiko / _d3d11_hook_and_cofm_shader_replacement.md
Last active January 3, 2021 01:11
d3d11 hook + cofm shader replacement
  1. compile dxgi.c & d3d11.c files - these create dxgi.dll and d3d11.dll that allows to dump & replace shaders.
cl.exe /nologo /O2 /W3 /MT dxgi.c /link /DLL /OUT:dxgi.dll /INCREMENTAL:NO kernel32.lib user32.lib
cl.exe /nologo /O2 /W3 /MT d3d11.c /link /DLL /OUT:d3d11.dll /INCREMENTAL:NO kernel32.lib user32.lib d3dcompiler.lib dxguid.lib shlwapi.lib
  1. put dxgi.dll and d3d11.dll files next to ChildrenOfMorta.exe

  2. create d3d11_shaders folder next to ChildrenOfMorta.exe and put ps_b1c05ceb9ca8a14c.hlsl into this folder.

@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++))
{
@mmozeiko
mmozeiko / astar.h
Last active December 29, 2023 10:18
generic A* in C
// generic A* pathfinding
//
// INTERFACE
//
// mandatory macros
#ifndef ASTAR_POS_TYPE
#error ASTAR_POS_TYPE should specify position type
@mmozeiko
mmozeiko / GLES.txt
Last active July 26, 2020 22:36
Nvidia Jetson Nano info
EGL_VERSION: 1.5
EGL_VENDOR: NVIDIA
EGL_EXTENSIONS:
EGL_EXT_buffer_age, EGL_EXT_client_sync,
EGL_EXT_create_context_robustness, EGL_EXT_output_base,
EGL_EXT_stream_acquire_mode, EGL_EXT_sync_reuse, EGL_IMG_context_priority,
EGL_KHR_config_attribs, EGL_KHR_create_context_no_error,
EGL_KHR_context_flush_control, EGL_KHR_create_context,
EGL_KHR_display_reference, EGL_KHR_fence_sync,
EGL_KHR_get_all_proc_addresses, EGL_KHR_partial_update,