love.graphics.newScreenshot replaces alpha with full opacity by default (issue #374, thanks Boolsheet)

Some additional overhead was added to newScreenshot because it doesn't use glPixelTransfer (not supported in ES2 / core GL3+, and like all GL functions has the slight potential to be buggy on some drivers). This choice might be revisited in the future.
This commit is contained in:
Alex Szpakowski
2013-03-12 20:48:40 -03:00
parent e869b71c43
commit d39bb315af
3 changed files with 13 additions and 6 deletions
+9 -4
View File
@@ -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;