+
+ SDL_Rect **res = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_OPENGL);
+ if ( (res == NULL) || (res == ((SDL_Rect **)-1)) || (res[0] == NULL) || (res[0]->w < 640) || (res[0]->h < 480) )
+ res = hardcoded_resolutions;
+
+ // reverse list (it was sorted biggest to smallest by SDL)...
+ int count;
+ for (count = 0; res[count]; count++)
+ {
+ if ((res[count]->w < 640) || (res[count]->h < 480))
+ break; // sane lower limit.
+ }
+
+ static SDL_Rect *resolutions_block = NULL;
+ resolutions_block = (SDL_Rect*) realloc(resolutions_block, sizeof (SDL_Rect) * count);
+ resolutions = (SDL_Rect**) realloc(resolutions, sizeof (SDL_Rect *) * (count + 1));
+ if ((resolutions_block == NULL) || (resolutions == NULL))
+ {
+ SDL_Quit();
+ fprintf(stderr, "Out of memory!\n");
+ return false;
+ }
+
+ resolutions[count--] = NULL;
+ for (int i = 0; count >= 0; i++, count--)
+ {
+ memcpy(&resolutions_block[count], res[i], sizeof (SDL_Rect));
+ resolutions[count] = &resolutions_block[count];
+ }
+
+ if (cmdline("showresolutions"))
+ {
+ printf("Resolutions we think are okay:\n");
+ for (int i = 0; resolutions[i]; i++)
+ printf(" %d x %d\n", (int) resolutions[i]->w, (int) resolutions[i]->h);
+ }