Screenshot in fullscreen

Hi, I have screenshots working in windowed mode, but for some reason in fullscreen the output image is just black.

Code from http://www.lwjgl.org/wiki/index.php?title=Taking_Screen_Shots

Any ideas?

Thanks,
roland

Got Problems with screenshots in fullscreen-modes too. Try using 3 Bytes per Pixel.

Hey, Thanks for the reply.
You got it working by doing this?
I changed it, it still doesn’t work. Although my windowed ones are 1/4 smaller than they were :slight_smile:
Edit: No they aren’t, it was just that one xD

Make sure NOT to flip the buffer?

It does not flip the buffer :clue:

It reads from the front buffer, meaning that you should call Display.update() and then read it back with that code. Could that be it?

Thanks for the reply.
Like this? Nope it doesn’t work :frowning:


Display.update();
GL11.glReadBuffer(GL11.GL_FRONT);
...

Ugh… My laptop still isn´t back so I can´t test it myself… Do you mind posting the full code? I might be able to figure something out. =S


public static void takeScreenShot()
	{
		//Display.update();
		GL11.glReadBuffer(GL11.GL_FRONT);
		int width = Display.getWidth();
		int height= Display.getHeight();
		int bpp = 3; // Assuming a 32-bit display with a byte each for red, green, blue, and alpha.
		ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp);
		GL11.glReadPixels(0, 0, width, height, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, buffer );
		
		File file = new File("media/screenshots/" + String.valueOf(System.currentTimeMillis()) + ".png"); // The file to save to.
		String format = "PNG"; // Example: "PNG" or "JPG"
		BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

		for(int x = 0; x < width; x++)
			for(int y = 0; y < height; y++)
			{
				int i = (x + (width * y)) * bpp;
				int r = buffer.get(i) & 0xFF;
				int g = buffer.get(i + 1) & 0xFF;
				int b = buffer.get(i + 2) & 0xFF;
				image.setRGB(x, height - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | b);
			}

		try {
			ImageIO.write(image, format, file);
		} catch (IOException e) { e.printStackTrace(); }
	}

Your code works fine here. :clue:

I wonder if you’d run into the same problems using FBOs?

Also, I’d suggest including this before reading RGB pixels, to be safe…

glPixelStorei(GL_PACK_ALIGNMENT, 1);

The code looks fine, and the pack alignment is only needed if the window you´re reading from is not a multiple of 4.

You also misunderstood what I meant about Display.update(). You don´t want to call Display.update() an extra time, you want to take the screenshot after calling Display.update() as usual. This could be a bug in your drivers, so try to update them. Another thing you can try is to specify the back buffer instea (GL_FRONT instead of GL_BACK) and read back just BEFORE calling Display.update().

My resolution is 1366x768 in fullscreen. Unfortunately glPixelStorei(GL_PACK_ALIGNMENT, 1); did not fix it.

theagentd using GL_BACK just before Display.update() worked!! ;D
thanks! :slight_smile:

I’d say it was a driver bug then.

Shouldn’t someone be reporting all these bugs?! Manufacturers are so incompetent…

@OP is your GPU either Intel or AMD/ATI?

So you are saying the setup I have now will only work for me because my driver is bugged? :confused:

Im using Intel HD graphics atm… my ATI radeon mobility HD always overheats my laptop

Intel and AMD/ATI have atrocious drivers…

Intel… Burn. In. Hell. Because OpenGL 1.4 drivers are HARD to write. Just ask NVidia. I mean, think how buggy their OpenGL 4.2 drivers must be…

No, I’m saying that both should work equally well. Display.update() copies the back buffer to the front buffer.

Render to back buffer --> Display.update(), copies to front buffer (= the screen) --> Read back front buffer --> BUG
Render to back buffer --> Read back back buffer --> WORKS

[quote=“theagentd,post:11,topic:38842”]
So in LWJGL the “back buffer” is GL_FRONT? That seems confusing…

[quote=“davedes,post:19,topic:38842”]

Ah, fail, I mixed them up. GL_FRONT is what is on the screen and is updated with Display.update(). GL_BACK is what you render to and then copy to GL_FRONT.