need help on screenshot (black when writing)...

Hello there, I really need some help.
To make a long story short,

  1. I can’t use the ordinary screenshot function because I am dealing with old libraries

I want to do two things!

  1. Taking a screenshot from a jogl-context (jake2.de) in the “display()” function.
  2. 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!!

writing image files requires some caution about BMP file codecs. Have you tried w/ PNG or JPG 2000 ? PNG is like the old PCX for C apps.

I also tried:


        ImageIO.write(image, "PNG", new File("../Desktop/myscreen.PNG"));
	//ImageIO.write(image, "JPEG", new File("../Desktop/myscreen.JPG"));
	//ImageIO.write(image, "gif", new File("../Desktop/myscreen.GIF"));
	//ImageIO.write(image, "BMP", new File("../Desktop/myscreen.BMP"));

With same result, every time I got a black 640x480 picture.
But the ByteBuffer bb contain values (I checked that).

I assume that I am doing something fundamentally wrong?!
But I dont know, thats why I hope that someone here could point to my failure.

Thanks for your help so far…

It seems, that you instanciate the image but never “fill” it. That’s why the image remains black.

I’d suggest you to simply use the Screenshot-class which shippes within the jogl-distribution.

Greets
Klemens