You need to copy data from the OpenGL buffer. I used this method:
FloatBuffer grabScreen(GL gl) { int w = SCREENWITDH; int h = SCREENHEIGHT; FloatBuffer bufor = FloatBuffer.allocate(w*h*4);
You need to use something similar to suit your OpenGL shell. This is an example of JOGL.
And so for the LWJGL wrapper:
private static synchronized byte[] grabScreen() { int w = screenWidth; int h = screenHeight; ByteBuffer bufor = BufferUtils.createByteBuffer(w * h * 3); GL11.glReadPixels(0, 0, w, h, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, bufor);
EDIT
This may be useful as well (itβs not completely mine, it should also be configured):
BufferedImage toImage(byte[] data, int w, int h) { if (data.length == 0) return null; DataBuffer buffer = new DataBufferByte(data, w * h); int pixelStride = 3; //assuming r, g, b, skip, r, g, b, skip... int scanlineStride = 3 * w; //no extra padding int[] bandOffsets = { 0, 1, 2 }; //r, g, b WritableRaster raster = Raster.createInterleavedRaster(buffer, w, h, scanlineStride, pixelStride, bandOffsets, null); ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB); boolean hasAlpha = false; boolean isAlphaPremultiplied = true; int transparency = Transparency.TRANSLUCENT; int transferType = DataBuffer.TYPE_BYTE; ColorModel colorModel = new ComponentColorModel(colorSpace, hasAlpha, isAlphaPremultiplied, transparency, transferType); BufferedImage image = new BufferedImage(colorModel, raster, isAlphaPremultiplied, null); AffineTransform flip; AffineTransformOp op; flip = AffineTransform.getScaleInstance(1, -1); flip.translate(0, -image.getHeight()); op = new AffineTransformOp(flip, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); image = op.filter(image, null); return image; }