Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (552)
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  
  Screenshots in LWJGL?  (Read 6515 times)
0 Members and 1 Guest are viewing this topic.
Offline adamp

Senior Newbie




-x-x-x-


« Posted 2003-02-05 17:36:44 »

Is it possible to take screenshots when using LWJGL?

Thanks in advance, Adam.
Offline vrm

Junior Member




where I should sign ?


« Reply #1 - Posted 2003-02-05 17:46:10 »

got the same trouble on Linux .. strange I was able to with gl4java Cheesy
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #2 - Posted 2003-02-05 18:04:24 »

A little proggy called Capture Express 2000 (win) can do it. You can dl it at www.download.com

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline adamp

Senior Newbie




-x-x-x-


« Reply #3 - Posted 2003-02-05 19:38:03 »

I thought about an screencapture-button in my program to save screenshots directly to disk...
But your suggestion will fit my needs for now,  too :-)

Thanks, Adam.
Online princec

JGO Kernel


Medals: 363
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #4 - Posted 2003-02-05 20:13:38 »

It's really, really, easy to do a gl.readPixels() call as well and write out images directly, which is what I do. I save them as raw format and convert them in PSP to jpegs, but you can just as easily use some AWT/ImageIO to write them out directly in the format you want.

Cas Smiley

Offline adamp

Senior Newbie




-x-x-x-


« Reply #5 - Posted 2003-02-05 20:25:49 »

Speed doesn't matter, so readPixels() would be good enough for now.
I found this in the JavaDocs:

void readPixels (int x, int y, int width, int height, int format, int type, int pixels)

But I don't know how I could use this to get all pixel values, since return type is void.
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #6 - Posted 2003-02-05 21:42:16 »

The "int pixels" at the end is a ByteBuffer pointer where OpenGL will store the grabbed data.

Try something like the following:

1  
2  
3  
4  
// Buffer size is width * height * 4 colour components (for GL.RGBA) * size of int (4 bytes)
IntBuffer buff = ByteBuffer.allocateDirect(width * height * 4 * 4).order(ByteOrder.nativeOrder()).asIntBuffer() ;
int buffh = Sys.getDirectBufferAddress(buff) ;
gl.readPixels(0, 0, width, height, GL.RGBA, GL.INT, buffh)


I haven't tested this, so there's probably something wrong with it, but you get the idea! Wink

Hellomynameis Charlie Dobbie.
Offline adamp

Senior Newbie




-x-x-x-


« Reply #7 - Posted 2003-02-06 10:00:41 »

I just downloaded the OpenGL specification, there it's documented
a little bit clearer than in the JavaDocs of LWJGL.
Thanks for your help, I'm going to test it...

Adam.
Offline vrm

Junior Member




where I should sign ?


« Reply #8 - Posted 2003-02-06 11:21:20 »

Quick Hack  Grin

BTW java.nio look like an island in middle of the API, it's useless with other java function, no way for create a BufferedImage from a nio Buffer ?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
                   // Buffer size is width * height * 4 colour components (for GL.RGBA) * size of int (4 bytes)
                 IntBuffer buff = ByteBuffer.allocateDirect(Display.getWidth() * Display.getHeight() * 4).order(ByteOrder.nativeOrder()).asIntBuffer();
                  int buffh = Sys.getDirectBufferAddress(buff) ;
                  _gl.readPixels(0, 0, Display.getWidth(), Display.getHeight(), GL.BGRA, GL.BYTE, buffh);
                  BufferedImage img = new BufferedImage(Display.getWidth(), Display.getHeight(), BufferedImage.TYPE_INT_RGB);

                  for( int ix=0;ix<Display.getWidth();ix++)
                        for( int iy=0;iy<Display.getHeight();iy++)
                        {
                              img.setRGB(ix,iy,buff.get((Display.getHeight()-iy-1)*Display.getWidth()+ix));
                        }
                  try
                  {
                        File out=new File("sc.png");
                        ImageIO.write(img,"png",out);
                  }
                  catch(Exception e)
                  {
                        e.printStackTrace();
                  }
Offline vrm

Junior Member




where I should sign ?


« Reply #9 - Posted 2003-02-06 11:22:37 »

look like I need to add a gamma correction ..
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline alexz

Senior Newbie




Java games rock!


« Reply #10 - Posted 2003-02-06 11:55:18 »

Alternatively you can use temporary int array as a middle layer between java.nio and java.awt... IntBuffer.get(int[] dst) and BufferedImage.setRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize) methods...
Offline adamp

Senior Newbie




-x-x-x-


« Reply #11 - Posted 2003-02-11 08:08:30 »

No that I implemented a simple skybox it was worth it to add
a screen capture method - thanks for all you help!
It works just fine, but the pictures don't have the right
contrast... how can I solve this (without a paint program)?

Adam.
Offline Spasi
« Reply #12 - Posted 2003-02-12 11:42:19 »

Use

1  
gl.readPixels(0, 0, Display.getWidth(), Display.getHeight(), GL.BGRA, GL.UNSIGNED_BYTE, buffh); 


instead and the colors will be fine. When using GL.BYTE it does a strange / 2 when grabbing the colors from the buffer and converting them to GL.BYTE. I don't know why. You can check out the exact conversions of every format in the OpenGL specification. For GL.UNSIGNED_BYTE it just grabs the exact values.

Spasi
Offline Spasi
« Reply #13 - Posted 2003-02-12 11:48:59 »

Grabbing the pixels to the buffer, converting the buffer to an array and creating a BufferedImage from it, sure is fast enough for a fullscreen capture, but saving this image as a .png (my favorite) takes much time. In my machine about 3-4 seconds. I would recommend using the new ImageIO formats released recently as an external API (you can find it at java.sun.com). I had some problems with it (it's still RC), but it's worth trying. It also supports some new kind of native stuff, accelerating IO (especially for PNGs).

That is if you want to provide easy capturing for your users. If you want it just for yourself, a raw format would be just fine, as princec suggests.

Spasi
Offline adamp

Senior Newbie




-x-x-x-


« Reply #14 - Posted 2003-02-12 12:46:46 »

I already use ImageIO and save the screenshots as
JPEG and also use GL.BGRA in the readPixels command.
But I used GL.BYTE instead of GL_UNSIGNED_BYTE.
It works fine now, thanks for your help...

Adam.
Offline gregorypierce

Senior Member




I come upon thee like the blue screen of death....


« Reply #15 - Posted 2003-02-12 23:14:36 »

I've got mine to the point where it only take 1-1.2 seconds per screenshot on a 2000+ Athlon.

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Online princec

JGO Kernel


Medals: 363
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #16 - Posted 2003-02-13 11:26:15 »

Whaaaaaat! My screenshots take 1-2 milliseconds!!
(But then I don't save them as JPEGs  Tongue )

Cas Smiley

Offline gregorypierce

Senior Member




I come upon thee like the blue screen of death....


« Reply #17 - Posted 2003-02-13 12:24:17 »

I could dump the raw pixel buffer to disk but I wanted them to be in a format that was immediately viewable.

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Online princec

JGO Kernel


Medals: 363
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #18 - Posted 2003-02-14 09:00:18 »

TGA?

Cas Smiley

Offline gregorypierce

Senior Member




I come upon thee like the blue screen of death....


« Reply #19 - Posted 2003-02-14 15:46:46 »

JPEG and PNG. I would have to resample Targa files to make them suitable for a website.

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #20 - Posted 2006-03-23 00:57:50 »

I've got a question here, but it's specifically about saving as a TGA. I pretty much want to convert frames from a 3D model into sprites of the model doing various things. I've got the models all loaded in and taking a sceenshot works, but I don't know how to turn everything that is not the model into part of the alpha channel for the TGA, thereby making it transparent. Anyone know how? I was thinking of changing the background to some obscure color and searching for any pixels matching that color, but I don't want to do anything like that because there is the off chance I will need the color I used.

See my work:
OTC Software
Online kappa
« League of Dukes »

JGO Kernel


Medals: 76
Projects: 15


★★★★★


« Reply #21 - Posted 2006-03-23 10:55:16 »

I've got a question here, but it's specifically about saving as a TGA. I pretty much want to convert frames from a 3D model into sprites of the model doing various things. I've got the models all loaded in and taking a sceenshot works, but I don't know how to turn everything that is not the model into part of the alpha channel for the TGA, thereby making it transparent. Anyone know how? I was thinking of changing the background to some obscure color and searching for any pixels matching that color, but I don't want to do anything like that because there is the off chance I will need the color I used.

for 3d models you can usually do this with a 3d modeling program i've seen in programs such as 3ds max you can render the image to a bitmap or tga if you wish with alpha for the background! you can also just take a screenshot and edit in say the GIMP, where you can just fill paint the background into alpha and save as tga.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #22 - Posted 2006-03-23 18:52:00 »

This is true, I could use a program, but I wanted to make my own that would save me a lot of time over doing it manually. Pretty much it just loads in the first frame of an animation, let's you choose as many camera angles as you like, and then saves each animation from each of those camera angles, thereby creating sprites. This way after some experimentation I could simply drag the 3D model into the application and have every single type of sprite I need automatically generated.

See my work:
OTC Software
Offline cborders

Junior Member





« Reply #23 - Posted 2006-03-23 19:01:19 »

If you are going to take the shot in away from anything else you could use the ZBuffer to decide what should be alpha and what should show.
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #24 - Posted 2006-03-25 21:03:11 »

If you choose an 8-bit alpha channel for your OpenGL context using the PixelFormat class and set the background color to one with zero alpha using glClearColor, then if you read back the frame buffer in GL_ABGR_EXT format into a Targa file with alpha then the unrendered background pixels will automatically be transparent in the resulting .tga. For a concrete example, look in the JOGL source code for Screenshot.java, in particular writeToTargaFile(File file, int width, int height, boolean alpha).
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.

CopyableCougar4 (22 views)
2014-08-22 19:31:30

atombrot (34 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (28 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (26 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (41 views)
2014-08-06 19:49:38
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!