[SDL] [PATCH] Function to get desktop resolution

Jon Colverson sdl at vcxz.co.uk
Fri Jan 28 14:59:17 PST 2005


Simon Roby wrote:
> IMHO it would be better to add support in SDL_SetVideoMode() to select
> the current desktop resolution by specifying zero in the first and
> second arguments. That solution would be logical since you can achieve
> the same with the bpp (ie. setting it to zero selects the current
> desktop depth), and it would avoid polluting the API with a new
> function.

I like the symmetry with the bitsperpixel argument, but it makes things 
rather messy if getting the current resolution fails. Right now I'm doing:
----
// hard-coded defaults if we can't do any better
int width = 1024;
int height = 768;
SDL_GetDesktopMode(&width, &height);
SDL_Surface* screen = SDL_SetVideoMode(
	width, height, bpp, flags);
if (!screen) { /* fail */ }
----

If it worked like you propose I'd have to do something like:
----
SDL_Surface* screen = SDL_SetVideoMode(0, 0, bpp, flags);
if (!screen) {
	screen = SDL_SetVideoMode(1024, 768, bpp, flags);
	if (!screen) { /* something really wrong, fail */ }
}
----

Alternatively, we could say that 0 for width and height means "use 
user's current resolution if possible, otherwise use highest available 
resolution". I don't like that much either, because it would make is 
impossible to do something like:
----
int width, height;
if (!SDL_GetDesktopMode(&width, &height)) {
	/* yuck, ask the user, hope they forgive me later */
}
----

-- 
Jon





More information about the SDL mailing list