实际上在MDX的例子框架里已经包括了全屏模式,但这个框架对初学者来说还是太大了,从里面找到要点还是不太容易的。
其实要领不复杂,就是要在创建Device之前恰当地设置好PresentParameters的一些域,其中包括:
Windowed要设成false;
BackBufferWidth和BackBufferHeight要设成显示器支持的一种模式,这个不能乱设;
BackBufferCount是后备缓冲数量,实用上至少为1;
FullScreenRefreshRateInHz设成0就可以了;
PresentationInterval可以简单地设成PresentInterval.Default;
BackBufferFormat也许要设,而且一定要是当前显卡支持的一种;
SwapEffect这个域则是窗口模式和全屏模式都要设的,一般设为SwapEffect.Discard比较好。
有了这些准备,就可以创建一个全屏模式的Device了,以下是C#代码片段。
1 PresentParameters presentParams = new PresentParameters();
2 presentParams.Windowed = false;
3 presentParams.SwapEffect = SwapEffect.Discard;
4 presentParams.BackBufferWidth = 640;
5 presentParams.BackBufferHeight = 480;
6 presentParams.BackBufferCount = 2;
7 presentParams.FullScreenRefreshRateInHz = 0;
8 presentParams.PresentationInterval = PresentInterval.Default;
9 presentParams.BackBufferFormat = Format.X8R8G8B8;
10 device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
2 presentParams.Windowed = false;
3 presentParams.SwapEffect = SwapEffect.Discard;
4 presentParams.BackBufferWidth = 640;
5 presentParams.BackBufferHeight = 480;
6 presentParams.BackBufferCount = 2;
7 presentParams.FullScreenRefreshRateInHz = 0;
8 presentParams.PresentationInterval = PresentInterval.Default;
9 presentParams.BackBufferFormat = Format.X8R8G8B8;
10 device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);