Game Development Community

Detecting *valid* resolutions?

by Vern Jensen · in Torque Game Builder · 12/20/2009 (4:37 am) · 7 replies

How does one determine what a *valid* resolution for setScreenMode() would be? I'm currently using this at game start-up to go full-screen at the desktop resolution, and yet this has turned out to set the screen to an invalid resolution on older systems, so users of my game complain that it doesn't start up. (In reality it does, they just can't see anything.)

I've found that these users have somewhat older systems, presumably with graphics cards that contain less video memory -- not enough memory to drive their display at its maximum resolution, or something along those lines.

So how do I detect what valid resolution my game can run at? While I can startup in some small window like 800x600 at startup, on systems like my iMac with a native 1680x1050 display, this is a tiny window, and many users may not think to check "Options" for other sizes. And even if they do, they'll see resolutions that will result in an unviewable game if they select them. Is there some function I can call to see if the system I'm running on can actually support the given resolution?

#1
12/21/2009 (8:25 pm)
From the lack of reply, am I to assume this is not possible, and I should just go the tried-and-true method of asking the user if they can see a dialog box once the game starts up, and if they don't click OK, I change to a lower resolution?
#2
12/24/2009 (5:45 am)
I've grappled with a problem similar to this in the past. Let me dig up a link. Here ya go. The thread is about me trying to constrain a fullscreen window to a specific aspect ratio, but in the process I had to write some engine code to pull valid resolution changes from the system.
#3
12/24/2009 (4:50 pm)
Christopher, I'm afraid you came up with a rather difficult solution to a very easy problem. It's rather easy to avoid stretched screens, even while in full-screen mode, by resizing the window's GUI bounds. Try my game Insectoid to see how this is handled:

www.actionsoft.com/games/insectoid/

Here is the code I use in my game:

$wideScreenIsOn = false;	// Default value

function toggleWidescreen()
{
	$wideScreenIsOn = !$wideScreenIsOn;
	handleWidescreenChange();
}

function setWidescreen(%isOn)
{
	$wideScreenIsOn = %isOn;
	handleWidescreenChange();
}

	// Call this when returning to original window size.
function resetWidescreen()
{
	%info = getRes();
	%width = getWord(%info, 0);
	%height = getWord(%info, 1);
	
		// Set everything to be that same resolution
	mainScreenGui.setExtent( %width, %height );
	sceneWindow2D.setExtent( %width, %height );
	sceneWindow2D.setPosition( 0, 0 );
}


	// NOTE: See "MainScreen.gui" in the "game/gui" folder for names of GUI elements
	// that we access directly here. ("sceneWindow2D" and "mainScreenGui")
	// I can add more GUI elements or rename them in that file.
function handleWidescreenChange()
{
	// Get the current resolution of our game *window* (not of the desktop)
		// NOTE: it's possible to be full-screen, and still a much lower resolution that the desktop res
	%info = getRes();
	%width = getWord(%info, 0);	// 1680
	%height = getWord(%info, 1);	// 1050
	
		// setExtent = set the size of the control
	mainScreenGui.setExtent( %width, %height );
	
	%info = sceneWindow2D.getExtent();
	%windowWidth = getWord(%info, 0);
	%windowHeight = getWord(%info, 1); 
	
	%ratio = 800 / 600;		// This is 1.333333333. Note that some displays may be LESS than OR MORE than this! (1.25, 1.6, etc.)
	%newWidth = mCeil( %height * %ratio );  // Determine what the "correct" width would be if aspect ratio > 1.33
	%newHeight = mFloor( %width / %ratio ); // Determine what the correct height would be if aspect ratio < 1.33
	
		// Is the window the correct size for the game anyway? Then don't allow any widescreen changes.
	%canHaveBlackBorders = (%newWidth != %windowWidth);
	
		// Also don't allow widescreen changes if the  aspect ratio of the display is already perfect (1.333333)
	if (%newWidth == %width)
		%canHaveBlackBorders = false;
	
		// Were we already widescreen? Then switch to black borders on the sides.
	if ($wideScreenIsOn == false && %canHaveBlackBorders)
	{
//		echo("Doing change.");
		
		// Put a black border on the sides? (Screen ratio is GREATER than 1.3333, such as 1.6 on my iMac)
		if (%newWidth < %windowWidth)
		{
			%borderSize = (%width - %newWidth) / 2; // i.e. (1680 - 1400) / 2 = 140  (size of black borders)
			
				// sceneWindow2D is a GUI control that is put INSIDE of the mainScreenGui control
			sceneWindow2D.setExtent( %newWidth, %height );
			sceneWindow2D.setPosition( %borderSize, 0 );
		}
		else	// Put a black border on the top and bottom (screen ratio is LESS than 1.3333!)
		{
			%borderSize = (%height - %newHeight) / 2;	// The black space goes at the *top* and *bottom* of the screen
			
			sceneWindow2D.setExtent( %width, %newHeight );
			sceneWindow2D.setPosition( 0, %borderSize );
		}
	}
	else
	{
			// Switch to fullscreen/widescreen (stretch or shrink to fit)
		sceneWindow2D.setExtent( %width, %height );
		sceneWindow2D.setPosition( 0, 0 );
	}
}


And here is my GUI code in game/gui/mainscreen.gui

%guiContent = new GuiControl(mainScreenGui) {
   canSaveDynamicFields = "0";
   Profile = "GuiBlackContentProfile";
   HorizSizing = "width";
   VertSizing = "height";
   Position = "0 0";
   Extent = "1024 768";
   MinExtent = "8 8";
   canSave = "1";
   Visible = "1";
   useVariable = "0";
   
   new t2dSceneWindow(sceneWindow2D) {
      canSaveDynamicFields = "0";
      Profile = "GuiContentProfile";
      HorizSizing = "width";
      VertSizing = "height";
      Position = "0 0";
	  Extent = "1024 768";
      MinExtent = "8 8";
      canSave = "1";
      Visible = "1";
      lockMouse = "0";
      useWindowMouseEvents = "1";
      useObjectMouseEvents = "1";
   };
};

#4
12/24/2009 (4:54 pm)
Also, it looks like your code in the other thread is Mac-specific?
#5
12/26/2009 (9:58 pm)
Yeah, I needed to make engine level changes, and I never got around to writing the Windows code. I seem to remember there being differences in how Windows and OS X handle the Window UI being resized, but for the life of me cannot remember exactly what was wrong.

Regardless, as far as I can tell you might still need to make source code changes if you want a list of the valid resolutions for the system the game is running on. If you end up going this route, I'd love if you could keep us up to date, it would be very helpful to see how this can be handled in Windows!
#6
12/26/2009 (10:04 pm)
I've just gone the "Easy" route -- switch to a given resolution, then present the user with a dialog box asking if this resolution is okay. The dialog times out after 15 seconds, switching them back to the old resolution, if they push nothing before the 15 sec expires. If they accept the res, the prefs are updated to record that this resolution is "safe".
#7
12/26/2009 (10:16 pm)
Heh, that definitely sounds like the sane solution. I've wasted more time trying to perfect that blasted resolution change menu than I even spent making a game!