Hello there, I really need some help.
To make a long story short,
- I can’t use the ordinary screenshot function because I am dealing with old libraries
I want to do two things!
- Taking a screenshot from a jogl-context (jake2.de) in the “display()” function.
- passing the information as a “variable” (a matrix, or an array of arrays) to another application.
Currently I am trying to get the data from the application.
But after glReadPixels I try to see if it was a success (by writing the content to a file), but it’s
always black!?
My code:
//allocate necessary storage
BufferedImage image = new BufferedImage(640,480,BufferedImage.TYPE_BYTE_GRAY);
//creating direct ByteBuffer
//ByteBuffer bb = ByteBuffer.allocateDirect(((DataBufferByte) image.getRaster().getDataBuffer()).getSize());
ByteBuffer bb = ByteBuffer.allocateDirect(1000000); // 100000 = dummyvalue
//jogl needs a sliced buffer
bb = bb.slice();
//write pixel-data to the ByteBuffer
gl.glReadPixels(80, 60, width, height, GL.GL_BGR, GL.GL_UNSIGNED_BYTE, bb);
try {
ImageIO.write(image, "BMP", new File("../Desktop/myscreen.BMP"));
} catch (Exception ie) {
ie.printStackTrace();
}
//result a black image named "myscreen.BMP"
Can anyone tell me, what am I doing wrong??
Why is the screen black?
Please explain it plain, to be honest I got no clue what am I doing there, because I only need that
screenshot, but Im not into graphics programming, and I dont have the time to dig into it :(.
And I know that there is a seriously fast screenshot function in this forum, I tested it, and it worked,
but I need the data in a variable which I can pass through another application, without writing the data to the disk
(due to performance issues).
I would be really glad if anyone could help me!!