adamp
Senior Newbie 
-x-x-x-
|
 |
«
Posted
2003-02-05 18:36:44 » |
|
Is it possible to take screenshots when using LWJGL?
Thanks in advance, Adam.
|
|
|
|
|
vrm
Junior Member  
where I should sign ?
|
 |
«
Reply #1 - Posted
2003-02-05 18:46:10 » |
|
got the same trouble on Linux .. strange I was able to with gl4java 
|
|
|
|
|
erikd
|
 |
«
Reply #2 - Posted
2003-02-05 19: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!
|
|
adamp
Senior Newbie 
-x-x-x-
|
 |
«
Reply #3 - Posted
2003-02-05 20: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.
|
|
|
|
|
princec
|
 |
«
Reply #4 - Posted
2003-02-05 21: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 
|
|
|
|
adamp
Senior Newbie 
-x-x-x-
|
 |
«
Reply #5 - Posted
2003-02-05 21: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.
|
|
|
|
|
cfmdobbie
|
 |
«
Reply #6 - Posted
2003-02-05 22: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
| 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! 
|
Hellomynameis Charlie Dobbie.
|
|
|
adamp
Senior Newbie 
-x-x-x-
|
 |
«
Reply #7 - Posted
2003-02-06 11: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.
|
|
|
|
|
vrm
Junior Member  
where I should sign ?
|
 |
«
Reply #8 - Posted
2003-02-06 12:21:20 » |
|
Quick Hack  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
| 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(); } |
|
|
|
|
|
vrm
Junior Member  
where I should sign ?
|
 |
«
Reply #9 - Posted
2003-02-06 12:22:37 » |
|
look like I need to add a gamma correction ..
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
alexz
Senior Newbie 
Java games rock!
|
 |
«
Reply #10 - Posted
2003-02-06 12: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...
|
|
|
|
|
adamp
Senior Newbie 
-x-x-x-
|
 |
«
Reply #11 - Posted
2003-02-11 09: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.
|
|
|
|
|
Spasi
|
 |
«
Reply #12 - Posted
2003-02-12 12: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
|
|
|
|
|
Spasi
|
 |
«
Reply #13 - Posted
2003-02-12 12: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
|
|
|
|
|
adamp
Senior Newbie 
-x-x-x-
|
 |
«
Reply #14 - Posted
2003-02-12 13: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.
|
|
|
|
|
gregorypierce
|
 |
«
Reply #15 - Posted
2003-02-13 00: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.comShe 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!
|
|
|
princec
|
 |
«
Reply #16 - Posted
2003-02-13 12:26:15 » |
|
Whaaaaaat! My screenshots take 1-2 milliseconds!! (But then I don't save them as JPEGs  ) Cas 
|
|
|
|
gregorypierce
|
 |
«
Reply #17 - Posted
2003-02-13 13: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.comShe 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!
|
|
|
princec
|
 |
«
Reply #18 - Posted
2003-02-14 10:00:18 » |
|
TGA? Cas 
|
|
|
|
gregorypierce
|
 |
«
Reply #19 - Posted
2003-02-14 16:46:46 » |
|
JPEG and PNG. I would have to resample Targa files to make them suitable for a website.
|
http://www.gregorypierce.comShe 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!
|
|
|
Eli Delventhal
|
 |
«
Reply #20 - Posted
2006-03-23 01: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.
|
|
|
|
kappa
|
 |
«
Reply #21 - Posted
2006-03-23 11: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.
|
|
|
|
|
Eli Delventhal
|
 |
«
Reply #22 - Posted
2006-03-23 19: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.
|
|
|
|
cborders
|
 |
«
Reply #23 - Posted
2006-03-23 20: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.
|
|
|
|
|
Ken Russell
|
 |
«
Reply #24 - Posted
2006-03-25 22: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).
|
|
|
|
|
|