Game Development Reference
In-Depth Information
One of the common pitfalls mentioned in this chapter are the aliasing and artifacts
that result from a client region size not matching the size of the swap chain frame
buffer. This normally occurs after the swap chain has been created and the associated
window resizes. To account for this, there is a ResetSwapChain() method in the
manager that will be executed when the window is resized using the event below.
private void ContextWindow_Resize(object sender, System.EventArgs e)
{
_manager.ResetSwapChain(_swapChain);
}
Finally, we hit the interesting snippet, the Render() method. It is here that we first
make sure the manager exists and is ready to render; if not, we skip the current
frame. After that, it is important to set the render and view states for the swap
chain in case they were altered by another swap chain in existence on the same
device. The example does not employ many render state settings, but it is important
to recalculate the projection, world, and view matrices so that the scene renders
correctly.
Rendering is then initiated with a call to BeginSwapChainRender() , passing in the
unique identifier for the swap chain created when the child window was first
loaded. Rendering then proceeds as normal, except at the very end there is a call to
EndSwapChainRender() instead of calling Present() on the device.
public void Render()
{
if (_manager == null)
return;
if (!_manager.Ready)
return;
CalculateProjection();
_manager.Device.Transform.World = Matrix.Identity;
Vector3 position = new Vector3(0.0f, 0.0f, -5.0f);
Vector3 target = new Vector3(0.0f, 0.0f, 0.0f);
Vector3 upVector = new Vector3(0.0f, 1.0f, 0.0f);
_manager.Device.Transform.View = Matrix.LookAtLH(position,
target,
upVector);
Search Nedrilad ::




Custom Search