[SDL] listing all video modes

Patrice Mandin mandin.patrice at wanadoo.fr
Fri Oct 29 07:56:04 PDT 2004


Le Wed, 27 Oct 2004 22:06:51 +0000 (UTC)
nate <write_nathan at yahoo.com> a écrit:

> I'm trying to find a way to enumerate all supported video modes
> (including different bit depths) on a system so that my users can choose
> the mode they want to run in.  I don't want them to have to wait while I
> try to set every one and test for success.  I thought about using
> SDL_VideoModeOK for every depth for every resolution supported, but
> different resolutions might be supported at differnt depths, so I'd
> still have to change modes to find the supported resolutions for each
> depth using SDL_ListModes (right?).  If I had an exhaustive list of
> every video mode every supported on a modern systems, I could
> SDL_VideoModeOK each one in turn, but I don't have that list.  If anyone
> has ideas, code, or a list of all modes I'd appreciate it.

You just have to feed SDL_ListModes() with a SDL_PixelFormat having the
bpp set to what you want. Something like that is a good base:

OhWonderfulSdlGiveMeAllModesAndIWillGiveYouMySoul()
{
  SDL_Rect **modes;
  SDL_PixelFormat format;
  int screen_flags;

  /* What type of video modes do I want ? */
  screen_flags = SDL_FULLSCREEN;

  /* List 8 bits modes */
  format.BitsPerPixel=8;
  modes=SDL_ListModes(&format, screen_flags);
  /* do whatever I want with this list of 8 bits modes */

  /* List 15 bits modes */
  format.BitsPerPixel=15;
  modes=SDL_ListModes(&format, screen_flags);
  /* do whatever I want with this list of 15 bits modes */

  /* List 16 bits modes */
  format.BitsPerPixel=16;
  modes=SDL_ListModes(&format, screen_flags);
  /* do whatever I want with this list of 16 bits modes */

  /* List 24 bits modes */
  format.BitsPerPixel=24;
  modes=SDL_ListModes(&format, screen_flags);
  /* do whatever I want with this list of 24 bits modes */

  /* List 32 bits modes */
  format.BitsPerPixel=32;
  modes=SDL_ListModes(&format, screen_flags);
  /* do whatever I want with this list of 32 bits modes */
}

-- 
Patrice Mandin
WWW: http://membres.lycos.fr/pmandin/
Programmeur Linux, Atari
Spécialité: Développement, jeux




More information about the SDL mailing list