Commit 9dc201d4484290986549b89ff9444766b2797b56

Sylvain 2022-03-21T10:41:14

Fixed bug #2962 - when SDL_RenderReadPixels format = 0, used format of the target texture include/SDL_render.h, format: "0 to use the format of the rendering target "

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index af38a8a..e67a06c 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -4177,7 +4177,11 @@ SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
     FlushRenderCommands(renderer);  /* we need to render before we read the results. */
 
     if (!format) {
-        format = SDL_GetWindowPixelFormat(renderer->window);
+        if (renderer->target == NULL) {
+            format = SDL_GetWindowPixelFormat(renderer->window);
+        } else {
+            format = renderer->target->format;
+        }
     }
 
     real_rect.x = (int)SDL_floor(renderer->viewport.x);