From 1d27b150b6372e81ecf00ba8671d6daa7c4a2da0 Mon Sep 17 00:00:00 2001 From: Ramiro Rojo Date: Tue, 25 Aug 2020 04:13:01 -0300 Subject: [PATCH 1/2] Fix read screen pixels --- src/rayfork-gfx-backend-opengl.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/rayfork-gfx-backend-opengl.c b/src/rayfork-gfx-backend-opengl.c index 08a81c6..a19d13a 100644 --- a/src/rayfork-gfx-backend-opengl.c +++ b/src/rayfork-gfx-backend-opengl.c @@ -2871,11 +2871,20 @@ RF_API void rf_gfx_read_screen_pixels(rf_color* dst, int width, int height) { for (rf_int x = 0; x < width; x++) { - dst[((height - 1) - y) * width + x] = dst[(y * width) + x]; // Flip line + int i = ((height - 1) - y) * width + x; + int j = (y * width) + x; + + // only flip screen pixels once + if (i > height / 2) + { + rf_color temp = dst[i]; + dst[i] = dst[j]; + dst[j] = temp; + } // Set alpha component value to 255 (no trasparent image retrieval) // NOTE: Alpha value has already been applied to RGB in framebuffer, we don't need it! - if (((x + 1) % 4) == 0) dst[((height - 1) - y) * width + x].a = 255; + if(dst[j].a == 0) dst[j].a = 255; } } } From b232ebd4d3c2b03853a0ef1ff2a117df8319b378 Mon Sep 17 00:00:00 2001 From: Ramiro Rojo Date: Tue, 25 Aug 2020 04:18:40 -0300 Subject: [PATCH 2/2] fix variable --- src/rayfork-gfx-backend-opengl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rayfork-gfx-backend-opengl.c b/src/rayfork-gfx-backend-opengl.c index a19d13a..f34096a 100644 --- a/src/rayfork-gfx-backend-opengl.c +++ b/src/rayfork-gfx-backend-opengl.c @@ -2875,7 +2875,7 @@ RF_API void rf_gfx_read_screen_pixels(rf_color* dst, int width, int height) int j = (y * width) + x; // only flip screen pixels once - if (i > height / 2) + if (y > height / 2) { rf_color temp = dst[i]; dst[i] = dst[j];