Game Development Reference
In-Depth Information
The swap chains are obviously in need of a valid device to render with, and that is
the responsibility of this method. A parent window is specified (either the MDI
parent form or the SDI form), and the device is created and bound to this window.
public void CreateDevice(Form containingWindow)
{
if (_device != null)
{
_device.Dispose();
_device = null;
}
PresentParameters presentParams = new PresentParameters();
presentParams.AutoDepthStencilFormat = DepthFormat.D16;
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.PresentationInterval = PresentInterval.Immediate;
presentParams.EnableAutoDepthStencil = true;
_device = new Device(0,
DeviceType.Hardware,
containingWindow,
CreateFlags.SoftwareVertexProcessing,
presentParams);
_device.DeviceLost += new EventHandler(DeviceLost);
_device.DeviceReset += new EventHandler(DeviceReset);
DeviceReset(null, null);
_ready = true;
}
The following method handles the device lost event. The only job of this method
is to flip the ready flag to false so that errors do not occur when the application
attempts to render with an invalid device.
private void DeviceLost(object sender, EventArgs e)
{
_ready = false;
}
Search Nedrilad ::




Custom Search