public synchronized void commit() { if (runnable != null) { return; } runnable = new Runnable() { @Override public void run() { GLEx.gl10.glReadPixels( x, (int) (LSystem.screenRect.height * LSystem.scaleHeight) - y - height, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buffer); for (int i = 0, ny = 0; i < height; i++, ny++) { for (int j = 0; j < width; j++) { final int pix = buffer.get(i * width + j); final int pb = (pix >> 16) & 0xff; final int pr = (pix << 16) & 0x00ff0000; final int pixel = (pix & 0xff00ff00) | pr | pb; drawPixels[(height - ny - 1) * width + j] = pixel; } } if (image == null) { image = new LImage(width, height, true); } else if (image != null && image.isClose()) { image.dispose(); image = null; image = new LImage(width, height, true); } image.setPixels(drawPixels, width, height); if (image.getWidth() != trueWidth || image.getHeight() != trueHeight) { LImage tmp = image.scaledInstance(trueWidth, trueHeight); if (image != null) { image.dispose(); image = null; } commit = tmp; } else { commit = image; } } }; LSystem.callScreenRunnable(runnable); }