Minimal D3D11 reference implementation: An uncluttered Direct3D 11 setup + basic rendering primer and API familiarizer. Complete, runnable Windows application contained in a single function and laid out in a linear, step-by-step fashion that should be easy to follow from the code alone. ~200 LOC. No modern C++, OOP or (other) obscuring cruft. View on YouTube
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #if defined(_WIN32) | |
| # include <Windows.h> | |
| #elif defined(__APPLE__) || defined(LINUX) | |
| # include <sys/mman.h> | |
| #endif | |
| #include <optional> | |
| #include "result.hpp" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This work (SDLblit.cpp, by Cory Bloyd) is free of known copyright restrictions. | |
| // https://creativecommons.org/publicdomain/zero/1.0/ | |
| #include <SDL.h> | |
| inline uint32_t argb(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { return (a<<24) | (r << 16) | (g << 8) | (b << 0); } | |
| int main(int argc, char *argv[]) { | |
| SDL_Init(SDL_INIT_VIDEO); | |
| SDL_Rect screenRect = { 0,0,1024,1024 }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <SDL.h> | |
| int main(void) { | |
| SDL_Init(SDL_INIT_AUDIO); | |
| // the representation of our audio device in SDL: | |
| SDL_AudioDeviceID audio_device; | |
| // opening an audio device: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .PHONY: all | |
| all: rot13.wasm | |
| %.wasm.full: %.c | |
| clang $< -g -o $@ | |
| %.wasm.dwarf: %.wasm.full | |
| llvm-dwarfdump $< > $@ | |
| %.wasm: %.wasm.full %.wasm.dwarf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Windows.h> | |
| #include <d3d11.h> | |
| #include <iostream> | |
| #include <vector> | |
| #include <thread> | |
| #include <mutex> | |
| #include <d3dcompiler.h> | |
| #pragma comment(lib, "dxgi.lib") | |
| #pragma comment(lib, "d3d11.lib") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <class _Ty> | |
| _NODISCARD /* constexpr */ _Ty _Common_lerp(const _Ty _ArgA, const _Ty _ArgB, const _Ty _ArgT) noexcept { | |
| // on a line intersecting {(0.0, _ArgA), (1.0, _ArgB)}, return the Y value for X == _ArgT | |
| const int _Finite_mask = (int{isfinite(_ArgA)} << 2) | (int{isfinite(_ArgB)} << 1) | int{isfinite(_ArgT)}; | |
| if (_Finite_mask == 0b111) { | |
| // 99% case, put it first; this block comes from P0811R3 | |
| if ((_ArgA <= 0 && _ArgB >= 0) || (_ArgA >= 0 && _ArgB <= 0)) { | |
| // exact, monotonic, bounded, determinate, and (for _ArgA == _ArgB == 0) consistent: | |
| return _ArgT * _ArgB + (1 - _ArgT) * _ArgA; |
This is inspired by https://fasterthanli.me/blog/2020/a-half-hour-to-learn-rust/
the command zig run my_code.zig will compile and immediately run your Zig
program. Each of these cells contains a zig program that you can try to run
(some of them contain compile-time errors that you can comment out to play
with)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| namespace YourNamespace | |
| { | |
| struct Routine | |
| { | |
| // Current "waiting time" before we run the next block | |
| float wait_for = 0; | |
| // Used during `rt_for`, which repeats the given block for X time |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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 |
