2013-07-13 23 views
0

我很难理解视口如何受到XNA全屏模式的影响。在窗口模式下一切正常,但是当我打电话给graphics.ToggleFullScreen()时,根据调用前后缓冲区宽度的大小,会发生不同的事情。这就是我认为潜在的相关代码。它拆分为两大类:XNA全屏:基于缓冲区宽度的不同行为

// in the Game class 
    GraphicsDeviceManager graphics; 
    Viewport defaultViewport; 
    Viewport mainViewport; 

     // in the constructor: 
     graphics = new GraphicsDeviceManager(this); 
     graphics.PreferredBackBufferWidth = Settings.BufferWidthInPixels; 
     graphics.PreferredBackBufferHeight = Settings.BufferHeightInPixels;    

     // in the initialize method, setting up the two viewports: 
     defaultViewport = GraphicsDevice.Viewport; 
     mainViewport = new Viewport(); 
     mainViewport.Width = (int)(Settings.DefaultBufferWidth * Settings.StretchFactor); 
     mainViewport.Height = (int)(Settings.DefaultBufferHeight * Settings.StretchFactor); 
     mainViewport.X = (Settings.BufferWidthInPixels - mainViewport.Width)/2; 
     mainViewport.Y = (Settings.BufferHeightInPixels - mainViewport.Height)/2; 

    // in the Settings class: 
    public static readonly int DefaultBufferWidth = 800; 
    public static readonly int DefaultBufferHeight = 480; 
    // the following two variables are what I change to get different window sizes and hence different performance in fullscreen mode: 
    public static readonly int BufferWidthInPixels = 1200; 
    public static readonly int BufferHeightInPixels = 800; 
    public static readonly float StretchFactor = Math.Min((float)BufferWidthInPixels/DefaultBufferWidth, (float)BufferHeightInPixels/DefaultBufferHeight); 
    public static readonly Vector3 ScreenScalingFactor = new Vector3(StretchFactor, StretchFactor, 1); 
    public static readonly Matrix BaseScreenSizeTransformation = Matrix.CreateScale(ScreenScalingFactor); 

我改变的唯一变量是BufferWidthInPixelsBufferHeightInPixels。以下是一些示例行为:
(800,480) - defaultViewport扩展为填满整个屏幕,而mainViewport停留在左上角。到目前为止没有问题,但理想情况下我希望mainViewport也可以扩展,或者至少在其他情况下居中。
(800,600) - 虽然屏幕居中,但defaultViewportmainViewport的大小都不变。屏幕的其余部分变成纯黑色。仍然不错,尽管理想情况下视口会扩大以填满屏幕。
(1200,800) - 程序挂起,将我的屏幕变为纯白灰色。一会儿出现任务栏,但我必须进入任务管理器并结束该过程,然后才能再次控制计算机。

任何有关任何这方面的意见将不胜感激;我无法弄清楚为什么全屏模式在这些情况下行为如此不同。我的显示器分辨率是1280x800,如果有帮助(请注意,这是而不是导致我的电脑挂起的分辨率;全屏按预期工作在1280x800)。

+0

你可能不使用真正的全屏,而只是增加视口尺寸来填满屏幕? – user1306322

+0

它可能不相关,但它是值得,如果你在全屏工作提 - 一个应用程序,即将进入全屏模式,第一次应执行下列操作之一:A-设置应用程序分辨率屏幕完美匹配分辨率,B - 在窗口应用程序中询问用户使用哪种分辨率。某些屏幕可能会对你设置的分辨率产生很大的挑剔。 (另外,请始终包含窗口选项!) – mcmonkey4eva

+0

哦,另外,使用'graphics.IsFullScreen = true; graphics.ApplyChanges();'而不是'ToggleFullScreen',以确保设置正确应用。 – mcmonkey4eva

回答

0

您的图形卡很可能只能在全屏幕下处理certian分辨率。您可以遍历SupportedDisplayModes来找出设备支持的内容。请注意,这包括刷新率,因此可能会有重复。

foreach (DisplayMode mode in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes) { 

}