View Full Version : capture opengl scene

08-24-2011, 08:56 AM
hello .
I use opengl and i would create the possibility of grab the current displayed image and export it to a .jpg or .png file.
is possible?

08-24-2011, 09:05 AM
jpg and png are complex file formats, you gonna need some library to export to these formats.

You can get a OpenGL frame using glReadPixels. Node that glReadPixels gives you raw data. If you need to export just for a quick look, take a look at PPM format.


08-24-2011, 02:58 PM
try this, while it doesn't save in jpg, it's pretty easy to implement and you can always convert them later to jpg with an external program


08-24-2011, 03:27 PM
I second that. A simple 12 byte header and you have saved your back buffer to a TGA file. The example posted is a neat example of how to do it.
Jpg and png are too complex for this kind of thing and best left as job for an art package.

08-24-2011, 04:04 PM
Another downside of JPG and PNG is that they can be relatively slow to compress; if you ever want to export frames for creating video, they might not be good choices (TGA on the other hand may bottleneck you on disk IO so it's a balancing act that you'll have to tune).