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 / pcg32.h
Last active February 5, 2024 10:46
simple standalone C headers for PCG random number generator
#pragma once
#include <stdint.h>
#define PCG_DEFAULT_MULTIPLIER_64 6364136223846793005ULL
#define PCG_DEFAULT_INCREMENT_64 1442695040888963407ULL
typedef struct {
uint64_t state;
} pcg32;
@mmozeiko
mmozeiko / shader.hlsl
Last active February 4, 2024 17:53
compute shader for rendering monospaced glyphs in grid
//
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
mmozeiko / image2clipboard.c
Last active October 12, 2022 18:10
example how to put RGBA image in clipboard
#define STB_IMAGE_STATIC
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h" // get from https://raw.githubusercontent.com/nothings/stb/master/stb_image.h
#include <windows.h>
int main(int argc, char* argv[])
{
int w, h;
stbi_uc* data = stbi_load(argv[1], &w, &h, NULL, 4);
@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 / sdl2_pixels.c
Last active March 3, 2024 10:19
drawing pixels with SDL
// on Windows compile with:
// cl.exe sdl2_pixels.c -Zi -Iinclude -link -incremental:no -subsystem:windows SDL2.lib SDL2main.lib shell32.lib
#include <SDL.h>
#include <math.h>
int main(int argc, char* argv[])
{
int width = 1280;
int height = 720;
@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 / 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 / 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 / build-mesa3d.md
Last active December 16, 2021 19:01
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 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