Handmade Network»Forums
70 posts
innovation through innovation™
Minimal D3D11
Edited by d7samurai on Reason: Initial post
New version of my minimal D3D11 reference implementation; an uncluttered Direct3D 11 setup and rendering primer for newcomers to the API:


No modern C++ / OOP / obscuring cruft. The source code is a complete, runnable C+ application contained in a single function (WinMain), laid out in a step-by-step fashion that should be easy to follow from the code alone (about 250 LOC). Win7 compatible. Produces this output:

Mārtiņš Možeiko
2202 posts / 1 project
Minimal D3D11
Edited by Mārtiņš Možeiko on
Some time back I wrote similar thing: https://git.handmade.network/snippets/19
Yours is a bit complete, mine is only rendering one triangle, but it has extra features:
* Plain C, no C++
* Does not require DirectD3 11.1, uses 11.0
* Optionally does not link to D3DCompiler_XXX.dll file
* Handles window resizing
* Handles GPU driver reset on present call

70 posts
innovation through innovation™
Minimal D3D11
Edited by d7samurai on
sure. i also have other, older examples that do those things - window resizing, device reset, d3d11.0, doesn't use d3dcompiler etc. e.g.


however, the main purpose of this particular implementation was to optimize for pedagogical simplicity; that's why i emphasize the fact that it's all a single function, for example. so the omittance of those aspects was quite deliberate. here, i wanted to streamline the conceptual flow from setup to actual 3d rendering in order to provide a straightforward overview of the d3d11 way - primarily for people already familiar with gpu programming, but new to d3d conventions and nomenclature. the tactical choices i made were informed by this guiding intent.

i did initially consider adding window resizing and device reset, but in the end decided against it as i see them as secondary concepts, not to mention that "device lost" ~never happens unpredictably in d3d11, and that it would only serve to add complexity and distract. in fact, in these reference examples there's no error handling whatsoever, for the same reasons.

d3d11.1 (assuming that was meant to mean d3d11_1.h, as opposed to FEATURE_LEVEL_11_1, since my example only requests FEATURE_LEVEL_11_0) is what i consider the minimum version of the d3d api worth bothering with. there's little, if anything, to be gained by using d3d11.0, even in terms of compatibility, as most 11.1 features are available in win7 with platform update anyway. i also specifically wanted to include the routine for "casting" to newer versions of Device and DeviceContext because that's going to be required for all recent api interfaces and something most people will need to do.

as for c vs c++.. i am not a plain c guy myself, as i see that as an unnecessary pain in the ass, but i do code in a very barebone "c+", aka "c with benefits", which i think is a better, more relevant target for a reference codebase like this. especially since it's d3d centric.

that said, i think it's great that you have a plain c alternative out there