ResChange Game Class

cubed2D
April 20th, 2007.

Ok, ill admit it might not seem like a big thing, but i personally hate it when games have crummy choice in screen resolutions! So, people of the XNA world, i present to you a class pulled from CrimsonEng, ResChange.

When i work with screen resolutions, i tend to use there silly standardisation names (things like QXGA), which are probably a mystery to most people! Never fear! Lets explore these strange acronyms!

Lets start with the easy letter, W stands for Wide surprisingly enough, (aspect ratio of 16:9 or 16:10 for those who care)

Q on the other hand, is a tad more difficult as it can stand for quarter or Quadruple. It depends on the size of the resolution, quarter means the resolution is a quarter the size of the base resolution (QVGA is a quarter of the size of VGA), where as a Quad resolution would be… you can see where this is going!

U and X are Ultra and eXtended, and H is for Hexadecatuple (or hex to you and me!)(and there’s a word you dont use every day!)

Now we can read the names, lets have a look at a list of resolutions that are provided by resChange. (well, we can learn them but it might be a better idea to print a small sheet out to attach to your moniter if you want to use this class… ohh the wonder of post it notes)

Normal
QQVGA 60×120
QVGA 320×240
VGA 640 × 480
SVGA 800×600
XGA 1024 × 768
SXGA 1280×1024
UXGA 1600×1200
QXGA 2048×1536
QSXGA 2560×2048
QUXGA 3200×2400
HXGA 4096×3072 (if your running at this res right now, i want you pc)
HSXGA 5120×4096
HUXGA 6400×4800 ( XD )

WideScreen
WXGA 1280×720
WSXGA 1440×900
WSXGA+ 1680×1050
WUXGA 1920×1200
WQXGA 2560×1600
WQSXGA 3200×2048
WQUXGA 3840×2400
WHXGA 5120×3200
WHSXGA 6400×4096
WHUXGA 7680×4800

TV
480i 640 x 480
720p 1280 x 720
1080p/i 1920 x 1080

whew! That’s a lot of resolutions! Bet your glad i wrote this for you now? (or not!). Just so you can get an idea of how these compare, have a look at this brilliant comparison image i found on Wikipedia.
video standards

How do we use resChange i hear you ask? Very simply! Add the name space to your using section, call SetGraphics(graphics); Then you can use any version of the resChange method you want to use. the main version uses a ScreenMode enum, wich basicly contains all the strandard names and maps them to there screen resolutions.

Again, ill admit that its a very simple class, but i find wrapping this kind of stuff in to a nice little package endlessly useful. I hope someone finds this useful!

Get The Code Here

note: some of the really really big resolutions (probably HXGA and silly bigger) may cause some odd error in xna, and thus your game wont run. This is because your graphics card cannot handle textures of that size! You can check your max texture size quite easily with tools like direct 3d caps

2 Responses

#1 Kevin - 05 May, 6:36 PM

Why not do something more concise with your regChange, that’s easier to read, easier to change, compiles to a smaller size, and is nicer to look at! :) Like this:

#region Using
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace NekoCake
{
#region enum
public enum ScreenMode
{
QQVGA, // {160, 120}
QVGA, // {320, 240},
VGA, // {640, 480},
SVGA, // {800, 600},
XGA, // {1024, 768},
SXGA, // {1280, 1024},
UXGA, // {1600, 1200},
QXGA, // {2048, 1536},
QSXGA, // {2560, 2048},
QUXGA, // {3200, 2400},
HXGA, // {4096, 3072},
HSXGA, // {5120, 4096},
HUXGA, // {6400, 4800},
WXGA, // {1280, 720},
WSXGA, // {1440, 900},
WSXGAplus, // {1680, 1050},
WUXGA, // {1920, 1200},
WQXGA, // {2560, 1600},
WQSXGA, // {3200, 2048},
WQUXGA, // {3840, 2400},
WHXGA, // {5120, 3200},
WHSXGA, // {6400, 4096},
WHUXGA, // {7680, 4800},
tv480i, // {640, 480},
tv720p, // {1280, 720},
tv1080p // {1920, 1080}
}
#endregion

#region main class
static class SetWindow
{
private static GraphicsDeviceManager graphics;

public static void resChange()
{
resChange(ScreenMode.WXGA);
}

public static void resChange(int x, int y)
{
graphics.PreferredBackBufferWidth = x;
graphics.PreferredBackBufferHeight = y;
graphics.ApplyChanges();
}

private static readonly int[,] resolutions =
new int[,] {
// Normal
{160, 120},
{320, 240},
{640, 480},
{800, 600},
{1024, 768},
{1280, 1024},
{1600, 1200},
{2048, 1536},
{2560, 2048},
{3200, 2400},
{4096, 3072},
{5120, 4096},
{6400, 4800},
// Widescreen
{1280, 720},
{1440, 900},
{1680, 1050},
{1920, 1200},
{2560, 1600},
{3200, 2048},
{3840, 2400},
{5120, 3200},
{6400, 4096},
{7680, 4800},
// TV
{640, 480},
{1280, 720},
{1920, 1080}
};

public static void resChange(ScreenMode mode)
{
resChange(resolutions[(int) mode, 0], resolutions[(int) mode, 1]);
}

public static void SetGraphics(GraphicsDeviceManager g)
{
graphics = g;
}
}
#endregion
}

#2 cubed2D - 06 May, 11:37 AM

I realy like the changes you made there, a good way to clean the code up, as for why i didnt do it? i dont have much time at the moment to work on my game engine, doing bits hear and there in between revision for my uni exams! i just pust code down as i think of it, so theres going to be a big clean up operation over the summer!

Leave a Comment

If this is your first comment it may be held for moderation. You can follow any responses to this entry through the RSS feed, or Trackback from your own site.