SDL_ListModes(3)

πŸ’– SDL_ListModes πŸ’–

okay bestie, we're in the SDL corner of the 3 manual, and today's main character is SDL_ListModes β€” she hands you a pointer to an array of every available screen dimension for the format and video flags you asked about. yes queen, resolution shopping. πŸŽ€


✨ NAME ✨

SDL_ListModes β€” returns a pointer to an array of available screen dimensions for the given format and video flags


🌸 SYNOPSIS 🌸

#include "SDL.h"

SDL_Rect **SDL_ListModes(SDL_PixelFormat *format, Uint32 flags);

πŸ¦‹ DESCRIPTION πŸ¦‹

So what she does is: she returns a pointer to an array of all the available screen dimensions for the format and video flags you passed in, and the list comes sorted largest to smallest. Big mode first, lil mode last, no notes. πŸ’…

Now, the return value is doing a lil three-way thing and you have to pay attention:

  • She returns NULL if there are no dimensions available for that particular format. like, nothing. empty. 😭
  • She returns -1 if any dimension is okay for the given format. (yes, that's the literal value -1 being used as a pointer, don't panic, that's just how she communicates.)
  • Otherwise you get the actual array pointer. slay.

If format is NULL, the mode list you get back will be for the format returned by SDL_GetVideoInfo()->vfmt. convenient fr fr. 🫢

The flags parameter is an OR'd combination of surface flags. Same flags as the ones used by SDL_SetVideoMode, and ngl they play a strong role in deciding which modes are valid. for example β€” if you pass SDL_HWSURFACE as a flag, only modes that support hardware video surfaces will be returned. it's giving filter. ✨


πŸŽ€ EXAMPLE πŸŽ€

SDL_Rect **modes;
int i;
.
.
.

/* Get available fullscreen/hardware modes */
modes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);

/* Check is there are any modes available */
if(modes == (SDL_Rect **)0){
  printf("No modes available!
");
  exit(-1);
}

/* Check if or resolution is restricted */
if(modes == (SDL_Rect **)-1){
  printf("All resolutions available.
");
}
else{
  /* Print valid modes */
  printf("Available Modes
");
  for(i=0;modes[i];++i)
    printf("  %d x %d
", modes[i]->w, modes[i]->h);
}
.
.

πŸ’œ SEE ALSO πŸ’œ

  • SDL_SetVideoMode
  • SDL_GetVideoInfo
  • SDL_Rect
  • SDL_PixelFormat

🫢 reminder bestie: NULL means no modes, -1 means every mode is fine. two very different moods, don't mix them up. πŸ’€

that's the whole page, you ate it, periodt. 🌈⭐ this one's from the SDL API Reference, dated Tue 11 Sep 2001, 23:01, and it lives at SDL_ListModes(3) β€” mwah, go forth and pick a resolution. πŸ‘‘πŸ’–

πŸ“¦ where this page comes from