Last active
August 24, 2025 05:57
-
-
Save d7samurai/032c63fd91c400bc33fb79c9e74adc46 to your computer and use it in GitHub Desktop.
Revisions
-
d7samurai revised this gist
Mar 24, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine D3D_FEATURE_LEVEL featurelevels[] = { D3D_FEATURE_LEVEL_11_0 }; DXGI_SWAP_CHAIN_DESC swapchaindesc = {}; swapchaindesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // non-srgb for simplicity here. see other minimal gists for srgb setup swapchaindesc.SampleDesc.Count = 1; swapchaindesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapchaindesc.BufferCount = 2; -
d7samurai revised this gist
Mar 21, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -39,7 +39,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, D3D11_CREATE_DEVICE_BGRA_SUPPORT, featurelevels, ARRAYSIZE(featurelevels), D3D11_SDK_VERSION, &swapchaindesc, &swapchain, &device, nullptr, &devicecontext); swapchain->GetDesc(&swapchaindesc); // get actual dimensions (see lines 94, 98) /////////////////////////////////////////////////////////////////////////////////////////////// -
d7samurai revised this gist
Mar 21, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -45,7 +45,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine ID3D11Texture2D* framebuffer; swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&framebuffer); // get the swapchain's frame buffer ID3D11RenderTargetView* framebufferRTV; -
d7samurai revised this gist
Mar 21, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -45,7 +45,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine ID3D11Texture2D* framebuffer; swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&framebuffer); // get the swapchain's buffer ID3D11RenderTargetView* framebufferRTV; -
d7samurai revised this gist
Mar 21, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -49,7 +49,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine ID3D11RenderTargetView* framebufferRTV; device->CreateRenderTargetView(framebuffer, nullptr, &framebufferRTV); // make a render target [view] from it FLOAT clearcolor[4] = { 0.1725f, 0.1725f, 0.1725f, 1.0f }; // RGBA -
d7samurai revised this gist
Mar 21, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -99,7 +99,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine D3D11_BUFFER_DESC constantbufferdesc = {}; constantbufferdesc.ByteWidth = sizeof(constants) + 0xf & 0xfffffff0; // constant buffer size must be multiple of 16 constantbufferdesc.Usage = D3D11_USAGE_IMMUTABLE; // never updated constantbufferdesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; D3D11_SUBRESOURCE_DATA constantbufferSRD = { constants }; -
d7samurai revised this gist
Mar 21, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ cbuffer constants : register(b0) { float2 rn_screensize; // 2 / width, -2 / height } struct vertexdesc -
d7samurai revised this gist
Mar 21, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -98,7 +98,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine float constants[2] = { 2.0f / swapchaindesc.BufferDesc.Width, -2.0f / swapchaindesc.BufferDesc.Height }; // precalc for simple screen coordinate transform in shader (instead of full-on projection matrix) D3D11_BUFFER_DESC constantbufferdesc = {}; constantbufferdesc.ByteWidth = sizeof(constants) + 0xf & 0xfffffff0; // constant buffer size must be multiple of 16 constantbufferdesc.Usage = D3D11_USAGE_IMMUTABLE; constantbufferdesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; -
d7samurai revised this gist
Mar 21, 2025 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -65,8 +65,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine D3D11_INPUT_ELEMENT_DESC inputelementdesc[] = // maps to vertexdesc struct in gpu.hlsl via semantic names ("POS", "COL") { { "POS", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, // float2 position (x, y) { "COL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, // float3 color (r, g, b) }; ID3D11InputLayout* inputlayout; -
d7samurai revised this gist
Mar 21, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ Plain 2D rendering in D3D11, without the distracting feature set of a [complete sprite renderer](https://gist.github.com/d7samurai/e51adec8a440126d028b87406556079b) and allowing [arbitrarily placed triangle vertices with absolute pixel coordinate positioning](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L152-L154) (there's really [no need](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-gpu-hlsl-L23) for the sometimes confusing complication of a full-on projection matrix pipeline for UI and 2D games). Like the [original Minimal D3D11](https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052), this one uses a canonical 1:1 `TRIANGLELIST` vertex buffer with input layout, so no fancy manual custom buffer fetching and in-shader instanced quad expansion here. As usual: complete, runnable single-function app. ~100 LOC. No modern C++, OOP or (other) obscuring cruft. This 'even simpler' variant renders solid color triangles; no texturing or alpha blending. For line drawing, change [this line](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L162) to: ```c devicecontext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); ``` -
d7samurai revised this gist
Mar 21, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ [](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46) Plain 2D rendering in D3D11, without the distracting feature set of a [complete sprite renderer](https://gist.github.com/d7samurai/e51adec8a440126d028b87406556079b) and allowing [arbitrarily placed triangle vertices with absolute pixel coordinate positioning](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L152-L154) (there's really [no need](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-gpu-hlsl-L23) for the sometimes confusing complication of a full-on projection matrix pipeline for UI and 2D games). Like the [original Minimal D3D11](https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052), this one uses a canonical 1:1 `TRIANGLELIST` vertex buffer with input layout, so no fancy manual custom buffer fetching and in-shader instanced quad expansion here. As usual: complete, runnable single-function app. ~100 LOC. No modern C++, OOP or (other) obscuring cruft. This 'even simpler' variant renders solid color triangles; no texturing or alpha blending. For line drawing, change [this line](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L172) to: ```c -
d7samurai revised this gist
Mar 21, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -159,7 +159,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine devicecontext->ClearRenderTargetView(framebufferRTV, clearcolor); devicecontext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); devicecontext->IASetInputLayout(inputlayout); devicecontext->IASetVertexBuffers(0, 1, &vertexbuffer, &stride, &offset); -
d7samurai revised this gist
Mar 21, 2025 . 1 changed file with 11 additions and 21 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -51,6 +51,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine device->CreateRenderTargetView(framebuffer, nullptr, &framebufferRTV); FLOAT clearcolor[4] = { 0.1725f, 0.1725f, 0.1725f, 1.0f }; // RGBA /////////////////////////////////////////////////////////////////////////////////////////////// ID3DBlob* vertexshaderCSO; @@ -89,6 +91,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine device->CreateRasterizerState(&rasterizerdesc, &rasterizerstate); D3D11_VIEWPORT viewport = { 0, 0, (float)swapchaindesc.BufferDesc.Width, (float)swapchaindesc.BufferDesc.Height, 0, 1 }; /////////////////////////////////////////////////////////////////////////////////////////////// float constants[2] = { 2.0f / swapchaindesc.BufferDesc.Width, -2.0f / swapchaindesc.BufferDesc.Height }; // precalc for simple screen coordinate transform in shader (instead of full-on projection matrix) @@ -122,21 +126,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine device->CreateBuffer(&vertexbufferdesc, nullptr, &vertexbuffer); UINT stride = sizeof(vertexdesc); UINT offset = 0; /////////////////////////////////////////////////////////////////////////////////////////////// while (true) { MSG msg; @@ -149,19 +143,15 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine /////////////////////////////////////////////////////////////////////////////////////////// D3D11_MAPPED_SUBRESOURCE vertexbufferMSR; devicecontext->Map(vertexbuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &vertexbufferMSR); { vertexdesc* vertex = (vertexdesc*)vertexbufferMSR.pData; vertex[0] = { 150, 100, 1.0f, 0.0f, 0.0f }; // vertex x, y, r, g, b vertex[1] = { 200, 250, 0.0f, 1.0f, 0.0f }; vertex[2] = { 100, 200, 0.0f, 0.0f, 1.0f }; } devicecontext->Unmap(vertexbuffer, 0); @@ -185,10 +175,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine /////////////////////////////////////////////////////////////////////////////////////////// devicecontext->Draw(3, 0); // draw 3 vertices /////////////////////////////////////////////////////////////////////////////////////////// swapchain->Present(1, 0); } } -
d7samurai revised this gist
Mar 21, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -151,7 +151,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine int vertexcount = 0; // start a new vertex batch every frame vertexbatch[vertexcount++] = { 150, 100, 1.0f, 0.0f, 0.0f }; // vertex x, y, r, g, b vertexbatch[vertexcount++] = { 200, 250, 0.0f, 1.0f, 0.0f }; vertexbatch[vertexcount++] = { 100, 200, 0.0f, 0.0f, 1.0f }; -
d7samurai revised this gist
Mar 21, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine D3D_FEATURE_LEVEL featurelevels[] = { D3D_FEATURE_LEVEL_11_0 }; DXGI_SWAP_CHAIN_DESC swapchaindesc = {}; swapchaindesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // non-srgb for simplicity here swapchaindesc.SampleDesc.Count = 1; swapchaindesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapchaindesc.BufferCount = 2; -
d7samurai revised this gist
Mar 20, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ Plain 2D rendering in D3D11, without the distracting feature set of a [complete sprite renderer](https://gist.github.com/d7samurai/e51adec8a440126d028b87406556079b) and allowing [arbitrarily placed triangle vertices with absolute pixel coordinate positioning](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L154-L156) (there's really [no need](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-gpu-hlsl-L23) for the sometimes confusing complication of a full-on projection matrix pipeline for UI and 2D games). Like the [original Minimal D3D11](https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052), this one uses a canonical 1:1 `TRIANGLELIST` vertex buffer with input layout, so no fancy manual custom buffer fetching and in-shader instanced quad expansion here. As usual: complete, runnable single-function app. ~100 LOC. No modern C++, OOP or (other) obscuring cruft. This 'even simpler' variant renders solid color triangles; no texturing or alpha blending. For line drawing, change [this line](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L172) to: ```c devicecontext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); ``` -
d7samurai revised this gist
Mar 19, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -91,7 +91,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine /////////////////////////////////////////////////////////////////////////////////////////////// float constants[2] = { 2.0f / swapchaindesc.BufferDesc.Width, -2.0f / swapchaindesc.BufferDesc.Height }; // precalc for simple screen coordinate transform in shader (instead of full-on projection matrix) D3D11_BUFFER_DESC constantbufferdesc = {}; constantbufferdesc.ByteWidth = sizeof(constants) + 0xf & 0xfffffff0; -
d7samurai revised this gist
Mar 19, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ [](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46) Plain 2D rendering in D3D11, without the distracting feature set of a [complete sprite renderer](https://gist.github.com/d7samurai/e51adec8a440126d028b87406556079b) and allowing [arbitrarily placed triangle vertices with absolute pixel coordinate positioning](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L154-L156) (there's really [no need](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-gpu-hlsl-L23) for the sometimes confusing complication of a full-on projection matrix pipeline for UI and 2D games). Like the [original Minimal D3D11](https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052), this one uses a canonical 1:1 `TRIANGLELIST` vertex buffer with input layout, so no fancy manual custom buffer fetching and in-shader instanced quad expansion here. As usual: complete, runnable single-function app. ~100 LOC. No modern C++, OOP or (other) obscuring cruft. This 'even simpler' variant renders solid color triangles; no texturing or alpha blending. For line drawing, change [this](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L172) to: ```c -
d7samurai revised this gist
Mar 19, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ [](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46) Plain 2D rendering in D3D11, without the distracting feature set of a [complete sprite renderer](https://gist.github.com/d7samurai/e51adec8a440126d028b87406556079b) and allowing [arbitrarily placed triangle vertices with absolute pixel coordinate positioning](https://gist.github.com/d7samurai/a8dc490c54a714f8385f512d95278e0b#file-cpu-cpp-L213-L248) (there's really [no need](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-gpu-hlsl-L23) for the sometimes confusing complication of a full-on projection matrix pipeline for UI and 2D games). Like the [original Minimal D3D11](https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052), this one uses a canonical 1:1 `TRIANGLELIST` vertex buffer with input layout, so no fancy manual custom buffer fetching and in-shader instanced quad expansion here. As usual: complete, runnable single-function app. ~100 LOC. No modern C++, OOP or (other) obscuring cruft. This 'even simpler' variant renders solid color triangles; no texturing or alpha blending. For line drawing, change [this](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L172) to: ```c -
d7samurai revised this gist
Mar 18, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ [](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46) Plain 2D rendering in D3D11, without the distracting feature set of a [complete sprite renderer](https://gist.github.com/d7samurai/e51adec8a440126d028b87406556079b) and allowing arbitrarily placed triangle vertices. Like the [original Minimal D3D11](https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052), this one uses a canonical 1:1 `TRIANGLELIST` vertex buffer with input layout, so no fancy manual custom buffer fetching and instanced quad expansion in shader etc, as well as absolute pixel coordinate positioning (there's really [no need](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-gpu-hlsl-L23) for the sometimes confusing complication of a full-on projection matrix pipeline for UI and 2D games). As usual: complete, runnable single-function app. ~100 LOC. No modern C++, OOP or (other) obscuring cruft. This 'even simpler' variant renders solid color triangles; no texturing or alpha blending. For line drawing, change [this](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L172) to: ```c -
d7samurai revised this gist
Mar 18, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ [](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46) Plain 2D rendering in D3D11, without the distracting feature set of a [complete sprite renderer](https://gist.github.com/d7samurai/e51adec8a440126d028b87406556079b) and allowing arbitrarily placed triangle vertices. Like the [original Minimal D3D11](https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052), this one uses a canonical 1:1 `TRIANGLELIST` vertex buffer with input layout, so no fancy manual custom buffer fetching and instanced quad expansion in shader etc, as well as absolute pixel coordinate positioning (there's really [no need](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-gpu-hlsl-L23) for the sometimes confusing complication of a full-on projection matrix pipeline for UI and 2D games). As usual: complete, runnable single-function app. No modern C++, OOP or (other) obscuring cruft. This 'even simpler' variant renders solid color triangles; no texturing or alpha blending. For line drawing, change [this](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L172) to: ```c -
d7samurai revised this gist
Mar 18, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ [](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46) Plain 2D rendering in D3D11, without the distracting feature set of a [complete sprite renderer](https://gist.github.com/d7samurai/e51adec8a440126d028b87406556079b). Like the [original Minimal D3D11](https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052), this one uses a canonical 1:1 `TRIANGLELIST` vertex buffer with input layout, so no fancy manual custom buffer fetching and instanced quad expansion in shader etc, as well as absolute pixel coordinate positioning (there's really [no need](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-gpu-hlsl-L23) for the sometimes confusing complication of a full-on projection matrix pipeline for UI and 2D games). As usual: complete, runnable single-function app. No modern C++, OOP or (other) obscuring cruft. This 'even simpler' variant renders solid color triangles; no texturing or alpha blending. For line drawing, change [this](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L172) to: ```c -
d7samurai revised this gist
Mar 18, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ [](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46) Plain 2D drawing in D3D11, without the distracting feature set of a [complete sprite renderer](https://gist.github.com/d7samurai/e51adec8a440126d028b87406556079b). Like the [original Minimal D3D11](https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052), this one uses a canonical 1:1 `TRIANGLELIST` vertex buffer with input layout, so no fancy manual custom buffer fetching and instanced quad expansion in shader etc, as well as absolute pixel coordinate positioning (there's really [no need](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-gpu-hlsl-L23) for the sometimes confusing complication of a full-on projection matrix pipeline for UI and 2D games). As usual: complete, runnable single-function app. No modern C++, OOP or (other) obscuring cruft. This 'even simpler' variant renders solid color triangles; no texturing or alpha blending. For line drawing, change [this](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L172) to: ```c -
d7samurai revised this gist
Mar 18, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Minimal D3D11 bonus material: even simpler 2D [](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46) -
d7samurai revised this gist
Mar 18, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -83,7 +83,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine /////////////////////////////////////////////////////////////////////////////////////////////// D3D11_RASTERIZER_DESC rasterizerdesc = { D3D11_FILL_SOLID, D3D11_CULL_NONE }; // CULL_NONE to be agnostic of triangle winding order ID3D11RasterizerState* rasterizerstate; -
d7samurai revised this gist
Mar 18, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -83,7 +83,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine /////////////////////////////////////////////////////////////////////////////////////////////// D3D11_RASTERIZER_DESC rasterizerdesc = { D3D11_FILL_SOLID, D3D11_CULL_NONE }; // we keep CULL_NONE to be agnostic of triangle winding order ID3D11RasterizerState* rasterizerstate; -
d7samurai revised this gist
Mar 18, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ Plain 2D rendering in D3D11, without the distracting feature set of a [complete sprite renderer](https://gist.github.com/d7samurai/e51adec8a440126d028b87406556079b). Like the [original Minimal D3D11](https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052), this one uses a canonical 1:1 `TRIANGLELIST` vertex buffer with input layout, so no fancy manual custom buffer fetching and instanced quad expansion in shader etc, as well as absolute pixel coordinate positioning (there's really [no need](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-gpu-hlsl-L23) for the sometimes confusing complication of a full-on projection matrix pipeline for UI and 2D games). As usual: complete, runnable single-function app. No modern C++, OOP or (other) obscuring cruft. This 'even simpler' variant renders solid color triangles; no texturing or alpha blending. For line drawing, change [this](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L172) to: ```c devicecontext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); ``` -
d7samurai revised this gist
Mar 18, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ Plain 2D rendering in D3D11, without the distracting feature set of a [complete sprite renderer](https://gist.github.com/d7samurai/e51adec8a440126d028b87406556079b). Like the [original Minimal D3D11](https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052), this one uses a canonical 1:1 `TRIANGLELIST` vertex buffer with input layout, so no fancy manual custom buffer fetching and instanced quad expansion in shader etc, as well as absolute pixel coordinate positioning (there's really [no need](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-gpu-hlsl-L23) for the sometimes confusing complication of a full-on projection matrix pipeline for UI and 2D games). As usual: complete, runnable single-function app. No modern C++, OOP or (other) obscuring cruft. This 'even simpler' variant renders solid color triangles (no texturing or alpha blending). For line drawing, change [this](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L172) to: ```c devicecontext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); ``` -
d7samurai revised this gist
Mar 18, 2025 . 1 changed file with 2 additions and 16 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -151,22 +151,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine int vertexcount = 0; // start a new vertex batch every frame vertexbatch[vertexcount++] = { 150, 100, 1.0f, 0.0f, 0.0f }; // x, y, r, g, b vertexbatch[vertexcount++] = { 200, 250, 0.0f, 1.0f, 0.0f }; vertexbatch[vertexcount++] = { 100, 200, 0.0f, 0.0f, 1.0f }; /////////////////////////////////////////////////////////////////////////////////////////// -
d7samurai revised this gist
Mar 18, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ Plain 2D rendering in D3D11, without the distracting feature set of a [complete sprite renderer](https://gist.github.com/d7samurai/e51adec8a440126d028b87406556079b). Like the [original Minimal D3D11](https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052), this one uses a canonical 1:1 `TRIANGLELIST` vertex buffer with input layout, so no fancy manual custom buffer fetching and instanced quad expansion in shader etc, as well as absolute pixel coordinate positioning (there's really [no need](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-gpu-hlsl-L23) for the sometimes confusing complication of a full-on projection matrix pipeline for UI and 2D games). As usual: complete, runnable single-function app. No modern C++, OOP or (other) obscuring cruft. This 'even simpler' variant renders solid color triangles (no texturing or alpha blending). For line drawing, change [this](https://gist.github.com/d7samurai/032c63fd91c400bc33fb79c9e74adc46#file-cpu-cpp-L186) to: ```c devicecontext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); ```
NewerOlder