Browse code

Switch to using SDL_CreateRGBSurface() SDL_CreateRGBSurfaceWithFormat() was introduced in SDL 2.0.5 whereas SDL_CreateRGBSurface() is available since SDL 2.0. This allows uxn to run on legacy systems where it's not possible to reach SDL 2.0.5 but prior versions are, such as Mac OS X Tiger.

Sevan Janiyan authored on 15/05/2023 02:08:59 • Devine Lu Linvega committed on 15/05/2023 02:34:55
Showing 1 changed files
... ...
@@ -273,12 +273,23 @@ static void
273 273
 capture_screen(void)
274 274
 {
275 275
 	const Uint32 format = SDL_PIXELFORMAT_RGB24;
276
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
277
+        /* SDL_PIXELFORMAT_RGB24 */
278
+        Uint32 Rmask = 0x000000FF;
279
+        Uint32 Gmask = 0x0000FF00;
280
+        Uint32 Bmask = 0x00FF0000;
281
+#else
282
+        /* SDL_PIXELFORMAT_BGR24 */
283
+        Uint32 Rmask = 0x00FF0000;
284
+        Uint32 Gmask = 0x0000FF00;
285
+        Uint32 Bmask = 0x000000FF;
286
+#endif
276 287
 	time_t t = time(NULL);
277 288
 	char fname[64];
278 289
 	int w, h;
279 290
 	SDL_Surface *surface;
280 291
 	SDL_GetRendererOutputSize(gRenderer, &w, &h);
281
-	surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 24, format);
292
+	surface = SDL_CreateRGBSurface(0, w, h, 24, Rmask, Gmask, Bmask, 0);
282 293
 	SDL_RenderReadPixels(gRenderer, NULL, format, surface->pixels, surface->pitch);
283 294
 	strftime(fname, sizeof(fname), "screenshot-%Y%m%d-%H%M%S.bmp", localtime(&t));
284 295
 	SDL_SaveBMP(surface, fname);