Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (541)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Screenshot in fullscreen  (Read 5572 times)
0 Members and 1 Guest are viewing this topic.
Offline roland
« Posted 2012-05-06 10:34:05 »

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
Offline matheus23

JGO Kernel


Medals: 114
Projects: 3


You think about my Avatar right now!


« Reply #1 - Posted 2012-05-06 10:41:02 »

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

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline 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  Smiley
Edit: No they aren't, it was just that one xD
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd

« JGO Bitwise Duke »


Medals: 366
Projects: 2
Exp: 8 years



« Reply #3 - Posted 2012-05-06 11:39:27 »

Make sure NOT to flip the buffer?

Myomyomyo.
Offline roland
« Reply #4 - Posted 2012-05-06 12:22:41 »

It does not flip the buffer  Clueless
Offline theagentd

« JGO Bitwise Duke »


Medals: 366
Projects: 2
Exp: 8 years



« 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.
Offline roland
« Reply #6 - Posted 2012-05-07 10:42:07 »

Thanks for the reply.
Like this? Nope it doesn't work Sad
1  
2  
3  
Display.update();
GL11.glReadBuffer(GL11.GL_FRONT);
...
Offline theagentd

« JGO Bitwise Duke »


Medals: 366
Projects: 2
Exp: 8 years



« 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.
Offline 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()
   {
      //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(); }
   }
Offline davedes
« Reply #9 - Posted 2012-05-09 03:39:46 »

Your code works fine here. Clueless

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!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd

« JGO Bitwise Duke »


Medals: 366
Projects: 2
Exp: 8 years



« Reply #10 - Posted 2012-05-09 09:35:49 »

Your code works fine here. Clueless

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.
Offline 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.
Offline roland
« Reply #12 - Posted 2012-05-10 12:17:53 »

theagentd using GL_BACK just before Display.update() worked!!  Grin
thanks! Smiley
Offline theagentd

« JGO Bitwise Duke »


Medals: 366
Projects: 2
Exp: 8 years



« Reply #13 - Posted 2012-05-10 13:59:12 »

I'd say it was a driver bug then.

Myomyomyo.
Online ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« 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?

Offline 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
Online ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #16 - Posted 2012-05-11 07:18:42 »

Intel and AMD/ATI have atrocious drivers...

Offline theagentd

« JGO Bitwise Duke »


Medals: 366
Projects: 2
Exp: 8 years



« 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.
Offline 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...

Offline theagentd

« JGO Bitwise Duke »


Medals: 366
Projects: 2
Exp: 8 years



« 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.
Offline 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()

Online ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« 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 Wink

Offline theagentd

« JGO Bitwise Duke »


Medals: 366
Projects: 2
Exp: 8 years



« 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 Wink
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.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Mr.CodeIt (10 views)
2014-12-27 04:03:04

TheDudeFromCI (13 views)
2014-12-27 02:14:49

Mr.CodeIt (25 views)
2014-12-23 03:34:11

rwatson462 (56 views)
2014-12-15 09:26:44

Mr.CodeIt (46 views)
2014-12-14 19:50:38

BurntPizza (92 views)
2014-12-09 22:41:13

BurntPizza (113 views)
2014-12-08 04:46:31

JscottyBieshaar (83 views)
2014-12-05 12:39:02

SHC (94 views)
2014-12-03 16:27:13

CopyableCougar4 (102 views)
2014-11-29 21:32:03
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!