This code worked for me:
// read
int bpp = 4;
int height = HEIGHT;
int width = WIDTH;
ByteBuffer screenBuffer = BufferUtils.createByteBuffer(width * height * bpp);
glReadPixels(0,0,width,height,GL_RGBA,GL_UNSIGNED_BYTE,screenBuffer);
// write
BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
for(int y = 0; y < height; ++y) {
for(int x = 0; x < width; ++x) {
int i = y * width * bpp + x * bpp;
int r = screenBuffer.get(i) & 0xFF;
int g = screenBuffer.get(i + 1) & 0xFF;
int b = screenBuffer.get(i + 2) & 0xFF;
image.setRGB(x,y,(0xFF << 24) | (r << 16) | (g << 8) | b);
}
}
// save
try {
ImageIO.write(image,"PNG",new File("test.png"));
}
catch(Throwable t) {
t.printStackTrace();
}