mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
Changing flipping broke Canvas:getImageData - fortunately, it also made it much simpler (fixes issue #311)
This commit is contained in:
@@ -280,20 +280,14 @@ namespace opengl
|
|||||||
{
|
{
|
||||||
static Matrix t;
|
static Matrix t;
|
||||||
const vertex * v = quad->getVertices();
|
const vertex * v = quad->getVertices();
|
||||||
|
|
||||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||||
drawv(t, v);
|
drawv(t, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
love::image::ImageData * Canvas::getImageData(love::image::Image * image)
|
love::image::ImageData * Canvas::getImageData(love::image::Image * image)
|
||||||
{
|
{
|
||||||
int row = 4 * width;
|
GLubyte pixels[4*width*height];
|
||||||
int size = row * height;
|
|
||||||
|
|
||||||
// see Graphics::newScreenshot. OpenGL reads from lower-left,
|
|
||||||
// but we need the pixels from upper-left.
|
|
||||||
GLubyte* pixels = new GLubyte[size];
|
|
||||||
GLubyte* screenshot = new GLubyte[size];
|
|
||||||
|
|
||||||
strategy->bindFBO( fbo );
|
strategy->bindFBO( fbo );
|
||||||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||||
@@ -302,16 +296,7 @@ namespace opengl
|
|||||||
else
|
else
|
||||||
strategy->bindFBO( 0 );
|
strategy->bindFBO( 0 );
|
||||||
|
|
||||||
GLubyte* src = pixels - row; // second line of buffer
|
love::image::ImageData * img = image->newImageData(width, height, (void*)pixels);
|
||||||
GLubyte* dst = screenshot + size; // end of buffer
|
|
||||||
|
|
||||||
for (int i = 0; i < height; ++i)
|
|
||||||
memcpy(dst -= row, src += row, row);
|
|
||||||
|
|
||||||
love::image::ImageData * img = image->newImageData(width, height, (void*)screenshot);
|
|
||||||
|
|
||||||
delete[] screenshot;
|
|
||||||
delete[] pixels;
|
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user