Game Development Reference
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.EnableAutoDepthStencil = true;
presentParams.DeviceWindow = renderTarget;
presentParams.BackBufferWidth = renderTarget.Width;
presentParams.BackBufferHeight = renderTarget.Height;
With the present parameters built, we can move on to building a swap chain
object. The following code shows how to do this, where the first parameter is a
reference to the Direct3D device, and the second parameter is a reference to the
PresentParameters structure that we just built.
SwapChain swapChain = new SwapChain(device, presentParams);
The next important piece of code to show is the rendering logic that is executed
each time a frame is rendered. This code is similar to a normal Direct3D applica-
tion, except the back buffer must be set as a render target, and the swap chain pre-
sents the frame to the screen, not the device itself.
public void RenderSwapChain(SwapChain swapChain, Control renderTarget)
using (Surface backBuffer = swapChain.GetBackBuffer(0,
// Perform rendering here without calling Device.Present()
Rendering is performed as normal, except Present() is called on the swap chain rather than the
Now that the basics have been covered about how to create and render a Direct3D
swap chain, it is time to expand on this topic and cover applicability towards MDI
and SDI applications.