@@ -0,0 +1,2216 @@
+package ca.blarg.gdx;%0A%0Aimport com.badlogic.gdx.Gdx;%0Aimport com.badlogic.gdx.files.FileHandle;%0Aimport com.badlogic.gdx.graphics.GL10;%0Aimport com.badlogic.gdx.graphics.Pixmap;%0Aimport com.badlogic.gdx.graphics.PixmapIO;%0A%0Aimport java.nio.ByteBuffer;%0A%0Apublic class Screenshot %7B%0A%09static int counter = 1;%0A%0A%09public static void take(String createInPath) %7B%0A%09%09String prefix;%0A%09%09if (Strings.isNullOrEmpty(createInPath))%0A%09%09%09prefix = %22screenshot%22;%0A%09%09else if (createInPath.endsWith(%22/%22))%0A%09%09%09prefix = createInPath + %22screenshot%22;%0A%09%09else%0A%09%09%09prefix = createInPath + %22/screenshot%22;%0A%0A%09%09try %7B%0A%09%09%09FileHandle file;%0A%09%09%09do %7B%0A%09%09%09%09file = new FileHandle(prefix + counter + %22.png%22);%0A%09%09%09%09counter++;%0A%09%09%09%7D while (file.exists());%0A%09%09%09Pixmap pixmap = getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);%0A%09%09%09PixmapIO.writePNG(file, pixmap);%0A%09%09%09pixmap.dispose();%0A%09%09%09Gdx.app.log(%22Screenshot%22, String.format(%22Saved screenshot to %25s%22, file.file().getAbsolutePath()));%0A%09%09%7D catch (Exception e) %7B%0A%09%09%7D%0A%09%7D%0A%0A%09public static void take() %7B%0A%09%09take(null);%0A%09%7D%0A%0A%09// Why this method instead of libgdx's own ScreenUtils.getFrameBufferPixmap() ?%0A%09// This one converts to a 24bit (RGB) PNG which seems to look right a lot more consistently.%0A%09// ScreenUtils.getFrameBufferPixmap() creates 32bit (RGBA) Pixmaps which tend to look a bit weird when%0A%09// the image contains some partially transparent pixels (we would rather assume a black background for any%0A%09// kind of partially transparent pixels for screenshot purposes).%0A%0A%09private static Pixmap getFrameBufferPixmap(int x, int y, int w, int h, boolean flipY) %7B%0A%09%09Gdx.gl.glPixelStorei(GL10.GL_PACK_ALIGNMENT, 1);%0A%0A%09%09final Pixmap pixmap = new Pixmap(w, h, Pixmap.Format.RGB888);%0A%09%09ByteBuffer pixels = pixmap.getPixels();%0A%09%09Gdx.gl.glReadPixels(x, y, w, h, GL10.GL_RGB, GL10.GL_UNSIGNED_BYTE, pixels);%0A%0A%09%09final int numBytes = w * h * 3;%0A%09%09byte%5B%5D lines = new byte%5BnumBytes%5D;%0A%09%09if (flipY) %7B%0A%09%09%09final int numBytesPerLine = w * 3;%0A%09%09%09for (int i = 0; i %3C h; i++) %7B%0A%09%09%09%09pixels.position((h - i - 1) * numBytesPerLine);%0A%09%09%09%09pixels.get(lines, i * numBytesPerLine, numBytesPerLine);%0A%09%09%09%7D%0A%09%09%09pixels.clear();%0A%09%09%09pixels.put(lines);%0A%09%09%7D else %7B%0A%09%09%09pixels.clear();%0A%09%09%09pixels.get(lines);%0A%09%09%7D%0A%0A%09%09return pixmap;%0A%09%7D%0A%7D

add Screenshot class (for taking screenshots programmatically, duh)