[SDL] [PATCH] Function to get desktop resolution

David Olofson david at olofson.net
Fri Jan 28 15:26:10 PST 2005


On Friday 28 January 2005 23.59, Jon Colverson wrote:
> 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 */ }
> }
> ----

How about this:
----
SDL_Surface* screen = SDL_SetVideoMode(-1024, -768, bpp, flags);
----

where the negative arguments mean "use the desktop resolution if 
possible, otherwise use labs(width), labs(height)?"


That said, I like plain 0, 0 much better for some reason. I can live 
with 0 and some #defined (negative) values having special meanings, 
but negative sizes...? Eww...! :-)


> 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 */
> }
> ----

Right; I think that's a different feature and should have a different 
interface. (Can't you just use SDL_ListModes() to get the highest 
available resolution? If that doesn't work on some system, I guess 
the information just isn't available, and then you can't do it 
anyway.)


//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
|  Free/Open Source audio engine for games and multimedia.  |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
   --- http://olofson.net --- http://www.reologica.se ---




More information about the SDL mailing list