SDL_ListModes vs SDL_VideoModeOK

I want to find the best available video mode available (using my own
subjective defionition of “best”). I have two tools available:
SDL_ListModes and SDL_VideoModeOK.

SDL_ListModes takes a SDL_PixelFormat* as argument. This is really
awkward. I don’t want to look for a specific pixel format, I just want
to look for a mode with the right color depth. I’m not even sure how to
construct an appropriate SDL_PixelFormat.

There’s also a note on the wiki that SDL_ListModes doesn’t always find
all available resolutions. This worries me.

The alternative is SDL_VideoModeOK. I could just go through a list of
commonly (and not-so-commonly) available resolutions and take the first
one that fits. I might miss the more obscure resolutions, but I don’t
have to construct a SDL_PixelFormat, and I generally shouldn’t have to
worry about supported resolutions not being listed.

Am I right in thinking that SDL_ListModes is seriously flawed and
SDL_VideoModeOK should be preferred? Should I try SDL_ListModes first
and SDL_VideoModeOK later as a last resort? Are there any other
options? How /do/ I construct an appropriate SDL_PixelFormat?–
Rainer Deyke - rainerd at eldwood.com

Rainer Deyke wrote:

SDL_ListModes takes a SDL_PixelFormat* as argument. This is really
awkward. I don’t want to look for a specific pixel format, I just
want to look for a mode with the right color depth. I’m not even sure
how to construct an appropriate SDL_PixelFormat.
Just pass NULL for format to get all modes.

Mikael Eriksson wrote:

Rainer Deyke wrote:

SDL_ListModes takes a SDL_PixelFormat* as argument. This is really
awkward. I don’t want to look for a specific pixel format, I just
want to look for a mode with the right color depth. I’m not even sure
how to construct an appropriate SDL_PixelFormat.

Just pass NULL for format to get all modes.

The wiki says, “If format is NULL, the current format of the video
device is used.” Looking at the implementation, this seems to be the
format of the current video surface, or the format of the desktop if
SDL_SetVideoMode was not yet called. Not quite what I am looking for,
since I am looking for a specific color depth which may or may not be
the same as the color depth of the desktop.

Looking at the implementation again, it seems like only the BitsPerPixel
field of the SDL_PixelFormat is actually used. This makes it very easy
to construct a correct SDL_PixelFormat, since I only have to set one field.

It also looks like my assumption that SDL_VideoModeOK is somehow safer
than SDL_ListModes is false, since SDL_VideoModeOK internally calls
SDL_ListModes.

So, to answer my own questions:

  • SDL_ListModes is to preferred over SDL_VideoModeOK.
  • The SDL_PixelFormat is constructed by initializing all fields to
    zero and then setting the BitsPerPixel field.–
    Rainer Deyke - rainerd at eldwood.com