Jon Watte

I have a fairly simple problem. I'd like to see if the screen is wider than 1280 or not, before deciding on a 1280x720 backbuffer or a 1024x640 backbuffer. The latter will make the game (in windowed mode) work better on 1280x800 or 1280x1024 displays, which are pretty darn common these days. (Meanwhile, for Xbox, I'll just hard-code 1280x720)

However, when I create the graphics device manager inside the constructor of my game, I can't seem to actually read the current display mode / adapter format in any way, because they are all NULL. So, to get this data, I have to create the device first. But to create the device, I have to first get the data. Catch 22!

I'd prefer not to have to resort to P/Invoke -- is there a way to do this within plain XNA




Re: XNA Framework Getting adapter format BEFORE device creation?

Jim Perry

I don't think you can do it with XNA if you want to do it before the GraphicsDevice is created, but you can use the .NET Framework. Put the necessary code in a separate file and just don't include it for the 360 version.

Screen[] screens = System.Windows.Forms.Screen.AllScreens;
int UpperBound = screens.GetUpperBound(0);

for (int Index = 0; Index <= UpperBound; Index++)
{
Console.WriteLine("Device Name: " + screens[Index].DeviceName);
Console.WriteLine("Type: " + screens[Index].GetType().ToString());
Console.WriteLine("Working Area: " + screens[Index].WorkingArea.ToString());
Console.WriteLine("Primary Screen: " + screens[Index].Primary.ToString());
}






Re: XNA Framework Getting adapter format BEFORE device creation?

Jon Watte

That's unfortunate; I had hoped for an XNA-only solution.
I guess it's off to connect again...






Re: XNA Framework Getting adapter format BEFORE device creation?

neogir

How about this:

        DisplayModeCollection dmc;
        bool wideScreenSupported;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);

            dmc = GraphicsAdapter.DefaultAdapter.SupportedDisplayModes;

            wideScreenSupported = false;
            foreach (DisplayMode dm in dmc)
            {
                if (dm.Width > 1024)
                {
                    wideScreenSupported = true;
                    break;
                }

            }

            if (wideScreenSupported)
            {
                graphics.PreferredBackBufferWidth = 1280;
                graphics.PreferredBackBufferHeight = 720;
            }
            else
            {
                graphics.PreferredBackBufferWidth = 1024;
                graphics.PreferredBackBufferHeight = 640;
            }
        }





Re: XNA Framework Getting adapter format BEFORE device creation?

Brian Bening

If you're looking for the current desktop resolution, you can get it from:

GraphicsAdapter.DefaultAdapter.CurrentDisplayMode

--Brian




Re: XNA Framework Getting adapter format BEFORE device creation?

Jon Watte

That's a winner! Thanks; I don't need that System.Windows.Forms reference now.