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 / incbin.c
Last active December 7, 2023 04:10
Include binary file with gcc/clang
#include <stdio.h>
#define STR2(x) #x
#define STR(x) STR2(x)
#ifdef _WIN32
#define INCBIN_SECTION ".rdata, \"dr\""
#else
#define INCBIN_SECTION ".rodata"
#endif
@mmozeiko
mmozeiko / q1.c
Created August 23, 2021 00:35
Quake 1 animated model rendering
// download glfw3 from https://www.glfw.org/download and then compile:
// cl.exe -O2 q1.c -Iinclude -link opengl32.lib glu32.lib lib-vc2019\glfw3dll.lib
#define _CRT_SECURE_NO_DEPRECATE
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
@mmozeiko
mmozeiko / ctime.c
Last active November 7, 2023 14:45
ctime.c
/* ========================================================================
$File: tools/ctime/ctime.c $
$Date: 2016/05/08 04:16:55PM $
$Revision: 7 $
$Creator: Casey Muratori $
$Notice:
The author of this software MAKES NO WARRANTY as to the RELIABILITY,
SUITABILITY, or USABILITY of this software. USE IT AT YOUR OWN RISK.
@mmozeiko
mmozeiko / win32_handmade.cpp
Last active September 24, 2023 02:08
win32_handmade.cpp with WASAPI from Day 19
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
THIS IS BAD WAY TO USE WASAPI. DO NOT USE MAYBE EXCEPT AS REFERENCE TO WASAPI FUNCTIONS.
/* ========================================================================
$File: $
$Date: $
$Revision: $
@mmozeiko
mmozeiko / ods.c
Created April 16, 2019 19:20
Example how to capture OutputDebugString on Windows
#include <windows.h>
#include <intrin.h>
#define Assert(x) do { if (!(x)) __debugbreak(); } while (0)
static struct
{
DWORD process_id;
char data[4096 - sizeof(DWORD)];
}* ods_buffer;
@mmozeiko
mmozeiko / x11_opengl.c
Last active July 19, 2023 06:02
setting up and using modern OpenGL 4.5 core context on X11 with EGL
// 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: 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
@mmozeiko
mmozeiko / d3d11_pixels.c
Last active June 18, 2023 20:42
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 / lz4.py
Created July 26, 2014 00:11
lz4 decompression in Python 2.x
# Warning: this implementation doesn't check if writes or reads will happen
# out of input/output buffer range, so that will generate IndexError exception
def LZ4_decompress(source, osize):
isize = len(source)
src = bytearray(source)
dst = bytearray(osize)
si = 0
@mmozeiko
mmozeiko / images2ico.py
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 # https://python-pillow.org/
@mmozeiko
mmozeiko / demo.c
Last active June 2, 2023 08:39
linux call stack
// gcc -g demo.c -ldl
#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>