Automatic Device Resets During a Resize

Anyone who's ever written a Direct3D application in C++ or DirectX for Visual Basic understands that normally, when the window of your application is resized, the device needs to be reset; otherwise, Direct3D will continue to render the scene at the same resolution as when the device was created, and the resulting image will be copied (and stretched to fit) onto the newly sized window. Managed DirectX is smart enough to realize when you've created your device with a Windows Form control, and can automatically reset the device for you when this control is resized. Naturally, you can revert back to the normal behavior and handle device resets yourself quite easily. There is an event attached to the device called "DeviceResizing", which occurs right before the automatic device reset code. By capturing this event, and setting the Cancel member of the EventArgs class passed in to true, you can revert to the default behavior. Add the following function to your sample:

 private void CancelResize(object sender, CancelEventArgs e) {     e.Cancel = true; } 

As you can see, this function does nothing more than say yes, we do want to cancel this action. Now, we need to hook up this event handler to our device so it knows not to perform this action. Add the following line of code immediately after the device creation:

 device.DeviceResizing += new CancelEventHandler(this.CancelResize); 

Now run the application once more and after it starts, maximize the window. As you can easily see, the triangle, while still there and in the same spot, looks horrible. The edges are jagged, and it's just not very nice looking at all. Go ahead and delete the last two sections of code we added. The default behavior of Managed DirectX handles the device resizing for you, and we might as well take advantage of it.



Managed DirectX 9 Graphics and Game Programming, Kick Start
Managed DirectX 9 Kick Start: Graphics and Game Programming
ISBN: B003D7JUW6
EAN: N/A
Year: 2002
Pages: 180
Authors: Tom Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net