|
matheus23
|
 |
«
Reply #1 - Posted
2012-05-06 10:41:02 » |
|
Got Problems with screenshots in fullscreen-modes too. Try using 3 Bytes per Pixel.
|
|
|
|
roland
|
 |
«
Reply #2 - Posted
2012-05-06 10:47:16 » |
|
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  Edit: No they aren't, it was just that one xD
|
|
|
|
Games published by our own members! Check 'em out!
|
|
theagentd
|
 |
«
Reply #3 - Posted
2012-05-06 11:39:27 » |
|
Make sure NOT to flip the buffer?
|
Myomyomyo.
|
|
|
roland
|
 |
«
Reply #4 - Posted
2012-05-06 12:22:41 » |
|
It does not flip the buffer 
|
|
|
|
theagentd
|
 |
«
Reply #5 - Posted
2012-05-06 13:05:07 » |
|
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?
|
Myomyomyo.
|
|
|
roland
|
 |
«
Reply #6 - Posted
2012-05-07 10:42:07 » |
|
Thanks for the reply. Like this? Nope it doesn't work  1 2 3
| Display.update(); GL11.glReadBuffer(GL11.GL_FRONT); ... |
|
|
|
|
theagentd
|
 |
«
Reply #7 - Posted
2012-05-07 13:34:30 » |
|
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
|
Myomyomyo.
|
|
|
roland
|
 |
«
Reply #8 - Posted
2012-05-09 00:13:32 » |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| public static void takeScreenShot() { GL11.glReadBuffer(GL11.GL_FRONT); int width = Display.getWidth(); int height= Display.getHeight(); int bpp = 3; 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"); String format = "PNG"; 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(); } } |
|
|
|
|
davedes
|
 |
«
Reply #9 - Posted
2012-05-09 03:39:46 » |
|
Your code works fine here.  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... 1
| glPixelStorei(GL_PACK_ALIGNMENT, 1); |
|
|
|
|
Games published by our own members! Check 'em out!
|
|
theagentd
|
 |
«
Reply #10 - Posted
2012-05-09 09:35:49 » |
|
Your code works fine here.  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... 1
| 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().
|
Myomyomyo.
|
|
|
roland
|
 |
«
Reply #11 - Posted
2012-05-10 12:13:02 » |
|
My resolution is 1366x768 in fullscreen. Unfortunately glPixelStorei(GL_PACK_ALIGNMENT, 1); did not fix it.
|
|
|
|
roland
|
 |
«
Reply #12 - Posted
2012-05-10 12:17:53 » |
|
theagentd using GL_BACK just before Display.update() worked!!  thanks! 
|
|
|
|
theagentd
|
 |
«
Reply #13 - Posted
2012-05-10 13:59:12 » |
|
I'd say it was a driver bug then.
|
Myomyomyo.
|
|
|
ra4king
|
 |
«
Reply #14 - Posted
2012-05-10 18:15:57 » |
|
Shouldn't someone be reporting all these bugs?! Manufacturers are so incompetent.....
@OP is your GPU either Intel or AMD/ATI?
|
|
|
|
roland
|
 |
«
Reply #15 - Posted
2012-05-11 07:06:45 » |
|
I'd say it was a driver bug then.
So you are saying the setup I have now will only work for me because my driver is bugged? :/ Im using Intel HD graphics atm... my ATI radeon mobility HD always overheats my laptop
|
|
|
|
ra4king
|
 |
«
Reply #16 - Posted
2012-05-11 07:18:42 » |
|
Intel and AMD/ATI have atrocious drivers...
|
|
|
|
theagentd
|
 |
«
Reply #17 - Posted
2012-05-11 12:57:25 » |
|
I'd say it was a driver bug then.
So you are saying the setup I have now will only work for me because my driver is bugged? :/ Im using Intel HD graphics atm... my ATI radeon mobility HD always overheats my laptop 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
|
Myomyomyo.
|
|
|
davedes
|
 |
«
Reply #18 - Posted
2012-05-12 19:47:14 » |
|
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(). So in LWJGL the "back buffer" is GL_FRONT? That seems confusing...
|
|
|
|
theagentd
|
 |
«
Reply #19 - Posted
2012-05-12 19:59:05 » |
|
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(). So in LWJGL the "back buffer" is GL_FRONT? That seems confusing... 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.
|
Myomyomyo.
|
|
|
davedes
|
 |
«
Reply #20 - Posted
2012-05-12 20:07:47 » |
|
Ah cool. I don't get why the solution works then.. Shouldn't we technically be reading pixels from GL_BACK before calling Display.update(), since that's where the game's being rendered to? 1 2 3 4 5 6
| game loop render game if screenshot requested glReadBuffer(GL_FRONT) <-- wouldn't GL_BACK make more sense? glReadPixels etc Display.update() |
|
|
|
|
ra4king
|
 |
«
Reply #21 - Posted
2012-05-12 21:38:55 » |
|
Nah sometimes the rendering isn't fully finished. Reading from the front is what the user is currently seeing so that makes more sense 
|
|
|
|
theagentd
|
 |
«
Reply #22 - Posted
2012-05-13 00:19:15 » |
|
Nah sometimes the rendering isn't fully finished. Reading from the front is what the user is currently seeing so that makes more sense  Don't confuse him. Calling glGetPixels() blocks the CPU until everything's rendered. It's not possible to get a half-rendered frame because the GPU wasn't finished yet. Ah cool. I don't get why the solution works then.. Shouldn't we technically be reading pixels from GL_BACK before calling Display.update(), since that's where the game's being rendered to? 1 2 3 4 5 6
| game loop render game if screenshot requested glReadBuffer(GL_FRONT) <-- wouldn't GL_BACK make more sense? glReadPixels etc Display.update() |
GL_FRONT = read what the player sees. It does make more sense, but that was when the bug occured, right?
|
Myomyomyo.
|
|
|
|