Introduction to Windows Graphics Programming using DirectX 11

  1. The Basic Windows Application SOURCEEXE ▫ Win32/C++
  2. Use Direct2D to Draw on the Window Surface SOURCEEXE ▫ Direct2D, render target
  3. The Bridge to Direct2D from Direct3D using DXGI SOURCEEXE ▫ Direct3D, DXGI, Direct2D
  4. An Image Processing Pipeline SOURCEEXE ▫ Direct2D, WIC
  5. A 2D Drawing Tool SOURCEEXE ▫ Direct2D, Win32, input
  6. Step Into 3D Using Direct3D SOURCEEXE ▫ Direct3D
  7. Minimal Direct3D: Draw A Triangle SOURCEEXE ▫ Direct3D, HLSL, shaders
  8. Texture-Map the Triangle SOURCEEXE ▫ Direct3D, texture-mapping
  9. A Camera for Point-of-View SOURCEEXE ▫ Direct3D, 3D geometry, vectors, transformation matrix, model-view-projection matrix, input
  10. Read In and Render 3D Geometry from OBJ Files SOURCEEXE ▫ Direct3D, 3D geometry, Wavefront OBJ
  11. Blinn-Phong Shading SOURCEEXE ▫ Direct3D, HLSL, lighting, Blinn-Phong shading

The Basic Windows Application SOURCEEXE ▫ Win32/C++

kwindow You need to a surface to draw on and a Windows graphics application presents a drawing surface inside a window; where else? This program lays out the structure of a Win32/C++ application. The binary shipped as a static library (kwindow.lib) that the rest of the projects link into. For a deeper, and therefore, clear understanding, the following are required reading : "A C++ Abstraction for a Window", explains the architecture of a windows program, and "What is A Window?", explains the concept of a window.


Use Direct2D to Draw on the Window Surface SOURCEEXE ▫ Direct2D, render target

d2d.hwndrt This is a simple program that shows how to render graphics on a window-surface using Direct2D. The program is short and therefor easily reveals the DirectX 11 programming patterns. The source file organization and constrcuts used will appear again and again as we program more complex rendering features. A point to note however is that rendering to a HWND-render-target is the past. The modern approach is to use a Direct2D device context. Direct3D too uses a Direct3D device context to call into different parts of the graphics pipeline and issuing draw calls. The program demonstrates the use of several Direct2D facilities: - render images as bitmaps, render text and render a moving pixel, in real-time, that bounces off the boundaries of a bitmp. The latter is achieved by writing to an in-memory bitmap buffer each frame. The image files are read in and decoded to create the in-memory bitmaps using the Windows Imaging Component API (WIC).


The Bridge to Direct2D from Direct3D using DXGI SOURCEEXE ▫ Direct3D, DXGI, Direct2D

d2d.dxgi The output of this program is just the bouncing pixel from the previous program. The focus here is to observe how to use the Direct2D device context instead of the HWND-render-target. That is the reason we have dropped the bitmap and text rendering. The overal architecture is to start with a Direct3D device abstraction, use DXGI to create a swap chain with back-buffers, and then with DXGI as a bridge, retrieve a Direct2D device context. This pattern will appear later on in our Direct3D programs.


An Image Processing Pipeline SOURCEEXE ▫ Direct2D, WIC

d2d.imageprocessor In this program we build an image-processing pipeline using Direct2D and WIC. The starting point shows how to read in an image file (PNG, JPG, etc.) using WIC and construct a WIC-bitmap and then a Direct2D-bitmap from the WIC-bitmap. Subsequently we acquire a WIC-lock on the WIC-bitmap to retrieve a pointer to the WIC-bitmap memory, and call the Map() function on the Direct2D-bitmap abstraction to map that bitmap-memory to CPU address-space and retrieve its memory-pointer. After writing to the memory, which in other words is the application of some image-processing algorithm, we release the lock on the WIC-bitmap and call Unmap() on the Direct2D bitmap to continue rendering them on the render-target. In this way we get a glimpse of an image-processing pipeline.


A 2D Drawing Tool SOURCEEXE ▫ Direct2D, Win32

d2d.paint In here we handle mouse and keyboard input, and combine them with Direct2D drwing facilities to build a multi-threaded, interactive graphics application. The program allows you to draw ellipses using your mouse, stacked on top of each other, select a partciular ellipse and wipe it from the drawing surface.


Step Into 3D Using Direct3D SOURCEEXE ▫ Direct3D

d3d.0 This program is ground zero of Direct3D graphics programming. Unlike the Direct2D code we have seen so far, this has been stripped of the C++ abstractions. In other words, we don't use any of the classes, but write out one long source file and encapsulate concepts in functions. A quick glance will make clear that the parameter lists of some of the functions are fairly long, which indicates that this style could be hard to maintain as the complexity of our DirectX 11 programs grow. What is useful about this program is that the explicit parameter passing helps the programmer understand how the data flows through the program. The program uses Direct3D to render 3D geometry and Direct2D to render text on the drawing surface. In this way we bridge our learning from Direct2D to Direct3D seeing how to draw using both parts of the DirectX 11 API. Subsequent Direct3D examples however drop the Direct2D drawing facility because using both Direct2D and Direct3D draw calls in a render loop severely hurts performance and therefore is not a recommended pattern the programmer should follow.


Minimal Direct3D: Draw A Triangle SOURCEEXE ▫ Direct3D, HLSL, shaders

d3d.triangle Renders a triangle demonstrating the simplest Direct3D rendering pipeline. There is one HLSL file containing both the vertex and pixel shader. The shader is loaded and compiled at run-time. The shader does not implement any model, view, or projection transformation so the triangle stretches as the window changes in size. Vertex positions are passed along to the rasterizer without modification and in the pixel shader vertices are colored arbitrarily.


Texture-Map the Triangle SOURCEEXE ▫ Direct3D, texture-mapping

d3d.texturemap The triangle is texture-mapped in this program. We use the WIC API to read in and decode an image file. A Direct3D texture is created from the WIC-bitmap and then the pixel shader samples it to color the geometry.


A Camera for Point-of-View SOURCEEXE ▫ Direct3D, 3D geometry, vectors, transformation matrix, model-view-projection matrix, input

d3d.camera This is a more comprehensive rendering pipeline implementation. Vector and matrix arithmetic is implemented, model, view and projection matrices built using those facilities, constant buffers are used to load transformation matrices into the GPU and made accessible to the vertex shader, keyboard input is handled to determine state change of geometry in the rendered world and to move the camera by applying transformation matrices modified by those inputs. In totality the program output presents an interactive surface where 3D geometry is rendered, manipulated and the camera moved, so as to create the effect of a first-person viewer who can move in 3D space; walk, turn, look left-right-up-down, using the keyboard.


Read In and Render 3D Geometry from OBJ Files SOURCEEXE ▫ Direct3D, 3D geometry, Wavefront OBJ

d3d.geometry The purpose of the program is to build a surface to render and view 3D geometry using all the features build so far and leaving out those that contribute to improving visual realism. For example, we leave out texture mapping and lighting constructs. The addition is a OBJ file reading facility, that enables rendering a wide variety of geometry data available in that file format. Eventually, the goal is to develop this codebase into surface for Geometry Processing.


Blinn-Phong Shading SOURCEEXE ▫ Direct3D, HLSL, lighting, Blinn-Phong shading

d3d.lighting So far we have colored the geometry arbitrarily so that we can see something on the drawing surface. To add visual realism to the scene we introduce lights by implementing the Blinn-Phong lighting model. It is simple to code and the mathematics is intuitive. In a pixel shader a diffuse and specular light intensity is computed, taking into account the location, color and intensity of the light source and the location of objects in space, and added to the pixel color information. In the output, a circular glare lights up the cube surface giving it a shiny appearance.