- if(texture_manager != NULL)
- texture_manager->save_textures();
-
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
-
- int flags = SDL_OPENGL;
- if(config->use_fullscreen)
- flags |= SDL_FULLSCREEN;
- int width = config->screenwidth;
- int height = config->screenheight;
- int bpp = 0;
-
- screen = SDL_SetVideoMode(width, height, bpp, flags);
- if(screen == 0) {
- std::stringstream msg;
- msg << "Couldn't set video mode (" << width << "x" << height
- << "-" << bpp << "bpp): " << SDL_GetError();
- throw std::runtime_error(msg.str());
+ static int desktop_width = 0;
+ static int desktop_height = 0;
+
+/* unfortunately only newer SDLs have these infos */
+#if SDL_MAJOR_VERSION > 1 || SDL_MINOR_VERSION > 2 || (SDL_MINOR_VERSION == 2 && SDL_PATCHLEVEL >= 10)
+ /* find which resolution the user normally uses */
+ if(desktop_width == 0) {
+ const SDL_VideoInfo *info = SDL_GetVideoInfo();
+ desktop_width = info->current_w;
+ desktop_height = info->current_h;
+ }
+#endif
+
+ double aspect_ratio = config->aspect_ratio;
+
+ // try to guess aspect ratio of monitor if needed
+ if (aspect_ratio <= 0) {
+// TODO: commented out because
+// 1) it tends to guess wrong if widescreen-monitors don't stretch 800x600 to fit, but just display black borders
+// 2) aspect ratios other than 4:3 are largely untested
+/*
+ if(config->use_fullscreen && desktop_width > 0) {
+ aspect_ratio = static_cast<double>(desktop_width) / static_cast<double>(desktop_height);
+ } else {
+*/
+ aspect_ratio = 4.0 / 3.0;
+/*
+ }
+*/
+ }
+
+ // use aspect ratio to calculate logical resolution
+ if (aspect_ratio > 1) {
+ SCREEN_WIDTH = static_cast<int> (600 * aspect_ratio + 0.5);
+ SCREEN_HEIGHT = 600;
+ } else {
+ SCREEN_WIDTH = 600;
+ SCREEN_HEIGHT = static_cast<int> (600 * 1/aspect_ratio + 0.5);