Game Development Reference
In-Depth Information
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,
BackBufferType.Mono))
{
swapChain.Device.SetRenderTarget(0, backBuffer);
// Perform rendering here without calling Device.Present()
swapChain.Present(renderTarget);
}
}
NOTE
Rendering is performed as normal, except Present() is called on the swap chain rather than the
device.
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.
 
Search Nedrilad ::




Custom Search