Make the window resizable, and set a reasonable initial size.
authorGuus Sliepen <guus@debian.org>
Sun, 9 Aug 2015 12:31:26 +0000 (14:31 +0200)
committerGuus Sliepen <guus@debian.org>
Sun, 9 Aug 2015 12:31:26 +0000 (14:31 +0200)
Now that SDL takes care of properly scaling the graphics, there is no
need for the window to be exactly 640x480. So allow the user to resize
it. To cope with high DPI screens, set the initial window size to a
multiple of 640x480 if it would fill less than half the width and
height.

src/init.cpp

index 1e947c0c90db7c3718f5e6da250205c9fb8a13c3..a274ad8a9d48a9f69c367eafe46cc0c01c5c3fbe 100644 (file)
@@ -286,14 +286,45 @@ void initSystem()
 
        graphics.screen = SDL_CreateRGBSurface(0, 640, 480, 32, 0xff0000, 0xff00, 0xff, 0xff000000);
 
-       graphics.window = SDL_CreateWindow("Blobwars: Metal Blob Solid", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, graphics.screen->w, graphics.screen->h, 0);
+       if (graphics.screen == NULL)
+       {
+               printf("Couldn't set 640x480 video mode: %s\n", SDL_GetError());
+               exit(1);
+       }
+
+       // Increase the size of the window if we have large desktop resolutions
+       SDL_DisplayMode displayMode{0};
+       SDL_GetDesktopDisplayMode(0, &displayMode);
+       int w = graphics.screen->w;
+       int h = graphics.screen->h;
+       while (displayMode.w > w * 2 && displayMode.h > h * 2)
+       {
+               w *= 2;
+               h *= 2;
+       }
+
+       graphics.window = SDL_CreateWindow("Blobwars: Metal Blob Solid", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, SDL_WINDOW_RESIZABLE);
+
+       if (graphics.window == NULL)
+       {
+               printf("Couldn't create %dx%d window: %s\n", w, h, SDL_GetError());
+               exit(1);
+       }
+
        graphics.renderer = SDL_CreateRenderer(graphics.window, -1, SDL_RENDERER_PRESENTVSYNC);
+
+       if (graphics.renderer == NULL)
+       {
+               printf("Couldn't create renderer: %s\n", SDL_GetError());
+               exit(1);
+       }
+
        SDL_RenderSetLogicalSize(graphics.renderer, graphics.screen->w, graphics.screen->h);
        graphics.texture = SDL_CreateTexture(graphics.renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, graphics.screen->w, graphics.screen->h);
 
-       if (graphics.window == NULL)
+       if (graphics.texture == NULL)
        {
-               printf("Couldn't set 640x480 video mode: %s\n", SDL_GetError());
+               printf("Could not create %dx%d texture: %s\n", graphics.screen->w, graphics.screen->h, SDL_GetError());
                exit(1);
        }