Skip to content

Instantly share code, notes, and snippets.

Avatar

Mārtiņš Možeiko mmozeiko

  • Epic Games / RAD Game Tools
  • Kirkland, WA
  • Twitter @mmozeiko
View GitHub Profile
@mmozeiko
mmozeiko / tls_client.c
Last active Oct 22, 2021
simple example of TLS socket client using win32 schannel api
View tls_client.c
#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>
@mmozeiko
mmozeiko / win32_opengl_multi.c
Last active Sep 23, 2021
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: 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 / q1.c
Created Aug 23, 2021
Quake 1 animated model rendering
View q1.c
// 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 / pcg32.h
Last active Aug 16, 2021
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
mmozeiko / shader.hlsl
Last active Aug 29, 2021
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
mmozeiko / image2clipboard.c
Last active Jul 7, 2021
example how to put RGBA image in clipboard
View image2clipboard.c
#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 Aug 13, 2021
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: 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 May 21, 2021
drawing pixels with SDL
View sdl2_pixels.c
// 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 Oct 20, 2021
setting up and using D3D11 in C
View win32_d3d11.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 <d3dcompiler.h>
#define _USE_MATH_DEFINES
#include <math.h>
@mmozeiko
mmozeiko / win32_opengl.c
Last active Oct 11, 2021
setting up and using modern OpenGL 4.5 core context on Windows
View win32_opengl.c
// 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