Bill Meltsner avatar Bill Meltsner committed e0234ed

Changing flipping broke Canvas:getImageData - fortunately, it also made it much simpler (fixes issue #311)

Comments (0)

Files changed (1)

src/modules/graphics/opengl/Canvas.cpp

 	{
 		static Matrix t;
 		const vertex * v = quad->getVertices();
-		
+
 		t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
 		drawv(t, v);
 	}
 
 	love::image::ImageData * Canvas::getImageData(love::image::Image * image)
 	{
-		int row = 4 * width;
-		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];
+		GLubyte pixels[4*width*height];
 
 		strategy->bindFBO( fbo );
 		glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
 		else
 			strategy->bindFBO( 0 );
 
-		GLubyte* src = pixels - row; // second line of buffer
-		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;
+		love::image::ImageData * img = image->newImageData(width, height, (void*)pixels);
 
 		return img;
 	}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.