Capture Screen

Started by HandLampe, March 29, 2006, 10:05:26

Previous topic - Next topic

HandLampe

Hello.

Iam new here. And really i dont know something of lwjgl.
And thats why i have just one question:
Is it possible to catrue the screen (with lwjgl) of any (OpenGL-based) Game, so i can take a movie from that?


THX

Matzon

yes
for some code you will have to search a bit

/queue faq/util entries kev? :)

HandLampe

thats not my problem.
But to get the right results of a search, you have to search with the right keywords. Thats my problem!
And believe me...i have searched alot. But iam afraid i searched with the wrong words.
So can u tell me, for what i have to look.

Fool Running

QuoteIs it possible to catrue the screen (with lwjgl) of any (OpenGL-based) Game, so i can take a movie from that?
Are you wanting to capture the screen of non-LWJGL applications, or just ones you write with LWJGL?
You can't do the first (to my knowledge).

EDIT: If you are just looking for a program to do that, try www.fraps.com
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

napier

You can capture the screen contents (the current frame) using the code below.  I'm not sure about capturing video, though you could look into the Quicktime Java API, which I believe will allow you to to build a video frame-by-frame.

This screencapture code is not optimized.  It works fine for one screen but for gnerating many frames you'd want to optimize it.


    /**
      * Save the contents of the current render buffer to a PNG image.  If the current
      * buffer is the framebuffer then this will work as a screen capture.  Can
      * also be used with the PBuffer class to copy large images or textures that
      * have been rendered into the offscreen pbuffer.
      * <P>
      * WARNING: this function is not optimized and hogs memory!  
      * You may need to run java with more memory (java -Xms360m -Xmx360)
      * <P>
      */
     public static void screenShot(int width, int height, String saveFilename) {
         // allocate space for RBG pixels
         ByteBuffer framebytes = GLApp.allocBytes(width * height * 3);
         int[] pixels = new int[width * height];
         int bindex;
         // grab a copy of the current frame contents as RGB (has to be UNSIGNED_BYTE or colors come out too dark)
         GL11.glReadPixels(0, 0, width, height, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, framebytes);
         // copy RGB data from ByteBuffer to integer array
         for (int i = 0; i < pixels.length; i++) {
             bindex = i * 3;
             pixels[i] =
                 0xFF000000                                          // A
                 | ((framebytes.get(bindex) & 0x000000FF) << 16)     // R
                 | ((framebytes.get(bindex+1) & 0x000000FF) << 8)    // G
                 | ((framebytes.get(bindex+2) & 0x000000FF) << 0);   // B
         }
         // free up this memory
         framebytes = null;
         // flip the pixels vertically (opengl has 0,0 at lower left, java is upper left)
         pixels = GLImage.flipPixels(pixels, width, height);
         try {
             // Create a BufferedImage with the RGB pixels then save as PNG
             BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
             image.setRGB(0, 0, width, height, pixels, 0, width);
             javax.imageio.ImageIO.write(image, "png", new File(saveFilename));
         }
         catch (Exception e) {
             System.out.println("GLApp.screenShot(): exception " + e);
         }
     }


     public static ByteBuffer allocBytes(int howmany) {
         return ByteBuffer.allocateDirect(howmany).order(ByteOrder.nativeOrder());
     }


This function calls another class to flip the pixels vertically:
   http://potatoland.org/code/gl/GLImage.java
penGL/Java/LWJGL demos and code: http://potatoland.org/code/gl

Nazca Visitor

You might try searching for an application what will capture a part of your screen over a period of time and convert to an avi file. Try Mr. Captor or Macromedia Captivate; you may be able to get a free trial download.

Your application would probably need to be windowed for it to work though.
igz r 4 n00bz