GLART week 12: Frame Buffer Objects, Screen Capture

It's possible to save the screen to an image, by capturing the current framebuffer pixels and writing them out to an image file format. For simplicity these examples use Java's built-in image IO functions to save a PNG image. The screen can also be copied to a texture. This allows you to use the framebuffer as a "canvas" by drawing to the framebuffer and saving the drawing to a texture for use later. This technique never draws anything to the actual screen. It can be used to create textures dynamically, or to save the state of the screen (useful when rendering with "trails"). If you need to generate large high resolution images, you can use an extension to OpenGL known as a Pbuffer to create a large virtual display. You can render to the Pbuffer as if it is a display, but the size of the Pbuffer is limited by the graphics card memory. To create potentially huge images, the glFrustum() command can be used to render the scene a piece at a time, in multiple tiles. Each tile can be saved as a separate screen shot. When pieced back together these tiles will form an image of the scene many times larger than the display resolution. Assigment: Reading: Red Book, Chapter 8, Images: pgs 294-300 Red Book, Chapter 9, Replacing all or Part of a texture Image: pgs 367-370 Examples: GLART_12_copyframe.java -- Copy from the frameBuffer to a texture GLART_12_screen_capture.java -- Save the screen image to a PNG file GLART_12_FBO.java -- Use a "FBO" (Frame Buffer Object) to render offscreen GLART_12_giantimage.java -- Create a high resolution image by rendering the scene as a set of tiles. NOTES: ================================================================= Pbuffer A "pbuffer" is like a canvas that behaves exactly like the screen but is not visible. It can be larger than the actual video display. Its size is limited only by the amount of RAM on the graphics card. Pbuffers are an early OpenGL extension and are very widely supported. Don't confuse them with pixel buffers, a more recent extenstion that is not yet as widely supported. glReadPixels() Use glReadPixels() to get pixels from the framebuffer. You can specify a region of the screen or the entire screen. This function is relatively slow because the pixels are copied out of the graphics card into the computers main memory, and is best used for infrequent operations, like screen captures. Pixels need to be flipped on the Y axis to be compatible with Java image formats. Also the pixels need to be massaged into an ARGB format, before saving to a file with the Java ImageIO class.