From 05c109a1d52db8293d8721337853043924feedae Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 8 May 2021 20:57:24 +0200 Subject: [PATCH] COGLES2Driver: fix swapped color screenshots --- source/Irrlicht/COGLES2Driver.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source/Irrlicht/COGLES2Driver.cpp b/source/Irrlicht/COGLES2Driver.cpp index fe960f3..f506114 100644 --- a/source/Irrlicht/COGLES2Driver.cpp +++ b/source/Irrlicht/COGLES2Driver.cpp @@ -2591,6 +2591,22 @@ COGLES2Driver::~COGLES2Driver() } delete [] tmpBuffer; + // also GL_RGBA doesn't match the internal encoding of the image (which is BGRA) + if (GL_RGBA == internalformat && GL_UNSIGNED_BYTE == type) + { + pixels = static_cast(newImage->getData()); + for (u32 i = 0; i < ScreenSize.Height; i++) + { + for (u32 j = 0; j < ScreenSize.Width; j++) + { + u32 c = *(u32*) (pixels + 4 * j); + *(u32*) (pixels + 4 * j) = (c & 0xFF00FF00) | + ((c & 0x00FF0000) >> 16) | ((c & 0x000000FF) << 16); + } + pixels += pitch; + } + } + if (testGLError(__LINE__)) { newImage->drop();