Introduction
This site walks through modern real-time rendering one small program at a time, from an empty window to image based physically based rendering. It is LearnOpenGL, the tutorial series by Joey de Vries, retold for
If you already know LearnOpenGL, you can read this as a translation guide: every chapter links its original, and the maths and techniques carry over unchanged. If you don't, you can read it on its own; nothing here assumes you have seen OpenGL.
Prerequisites
Direct3D is an API, not a language, so we need one to call it from. Ours is rin. It compiles to C and reads much like it: procedures, structs, pointers and arrays, no hidden allocation and no runtime. If you can read C, you can read every program here after a minute with the language page. The few spellings that differ are explained where they first show up, chiefly these:
- declarations put the name first:
count: i32 = 0;, andmain: proc() -> i32 = { ... } x&takes an address, andp[0]reads through a pointercast(x, f32)converts, andshrandshlare the shift operators
Direct3D's own interfaces are COM objects. From C, and so from rin, a method call puts the object first: ID3D11Device_CreateBuffer(device, ...) is what C++ writes as device->CreateBuffer(...). The next chapter says more.
We also use some mathematics along the way: vectors, matrices, a little trigonometry, and for PBR a few integrals. Each is introduced when it is needed and explained as far as the chapter needs it, with pointers to fuller treatments. Most of it is easier to use than to derive, and using it is enough to follow along.
Structure
The menu on the left lists the chapters in order, grouped into sections, the same sections LearnOpenGL has with "Advanced OpenGL" renamed. Read them top to bottom: each one builds on the program and the ideas of the one before. Every chapter explains the theory first, then builds it up in code, ending with a link to the complete program, some exercises, and further reading.
Each chapter is one .rin file that opens its own window, creates its own device, loads its own data and runs its own loop, with its HLSL shaders in the same folder. Nothing is hidden in a framework. The only shared code is what LearnOpenGL also shares: small stand-ins for the libraries it uses (GLFW, GLAD, GLM, stb_image) and its helper headers for shaders, the camera and models. All of the source can be read here in the code viewer, linked from each chapter, or on GitHub.
Where LearnOpenGL splits a lesson into several programs (an indexed triangle next to the plain one, a textured PBR scene next to the plain spheres), ours keeps them in one program and switches between them with Tab or the number keys. The window's title names the current mode, and the chapter says which key does what.
To keep the text easy to scan, a few conventions are used throughout.
Boxes
Code
Code appears in dark boxes, highlighted, rin for the programs and HLSL for the shaders:
// An immutable buffer: filled once at creation, never written by the CPU again.
create_buffer: proc(device: *ID3D11Device, bind: UINT, data: *const void, size: u64) -> *ID3D11Buffer = {
The snippets are copied from the real programs, so they always match what you will find in the full source.
Colour hints
Some words are coloured to show what kind of thing they are:
Definition : green words mark a term being defined, one you will meet again.Program structure : red words are functions and procedures, such asD3D11CreateDeviceAndSwapChain .- Variables: blue words are variables, fields and constants, such as D3D11_USAGE_IMMUTABLE.
Building the lessons
You will need Windows, the rin compiler, and the toolchain rin uses to build C: CMake, Ninja, clang-cl and the Windows SDK. With those in place, one command builds all 38 programs:
git clone https://github.com/IbrahimHindawi/rin-dx11
cd rin-dx11
rin build
build\cmake\hello_triangle.exe
Creating a window goes through the setup in detail. Every lesson uses the same controls once there is a camera to move: W, A, S and D with Space and Shift to fly, the right mouse button held down to look around, the mouse wheel to zoom, and Escape to quit.
Credit
The tutorial this follows is Joey de Vries' LearnOpenGL, also available as a book, with its code on GitHub. Its chapters, choice of examples and much of the way each subject is explained come from there, along with the textures, models and HDR environment the lessons load, and the diagrams marked as LearnOpenGL's. LearnOpenGL is licensed CC BY-NC 4.0, and so is everything here. Thank you, Joey: a great many of us learned graphics from your site.
Now that the layout is familiar, head on to Getting started.