diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index bb847c5da..b581cef79 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -1070,7 +1070,7 @@ void Graphics::polygon(DrawMode mode, const float *coords, size_t count) } } -love::image::ImageData *Graphics::newScreenshot(love::image::Image *image) +love::image::ImageData *Graphics::newScreenshot(love::image::Image *image, bool copyAlpha) { int w = getWidth(); int h = getHeight(); @@ -1084,16 +1084,21 @@ love::image::ImageData *Graphics::newScreenshot(love::image::Image *image) glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + if (!copyAlpha) + { + // Replace alpha values with full opacity. + for (int i = 3; i < size; i += 4) + pixels[i] = 255; + } + // OpenGL sucks and reads pixels from the lower-left. Let's fix that. GLubyte *src = pixels - row, *dst = screenshot + size; for (int i = 0; i < h; ++i) - { memcpy(dst-=row, src+=row, row); - } - love::image::ImageData *img = image->newImageData(w, h, (void *)screenshot); + love::image::ImageData *img = image->newImageData(w, h, (void *) screenshot); delete [] pixels; delete [] screenshot; diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index e8429106a..6b5925d10 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -461,8 +461,9 @@ public: /** * Creates a screenshot of the view and saves it to the default folder. * @param image The love.image module. + * @param copyAlpha If the alpha channel should be copied or set to full opacity (255). **/ - love::image::ImageData *newScreenshot(love::image::Image *image); + love::image::ImageData *newScreenshot(love::image::Image *image, bool copyAlpha = true); void push(); void pop(); diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index be49e5cc2..bc47c9707 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -839,7 +839,8 @@ int w_getMaxPointSize(lua_State *L) int w_newScreenshot(lua_State *L) { love::image::Image *image = luax_getmodule(L, "image", MODULE_IMAGE_T); - love::image::ImageData *i = instance->newScreenshot(image); + bool copyAlpha = luax_optboolean(L, 1, false); + love::image::ImageData *i = instance->newScreenshot(image, copyAlpha); luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)i); return 1; }