Save to image file

I’d like to be able to draw to the p-buffer then save the scene to a file, e.g. in jpeg format. I have a demo program that draws to the p-buffer, but I don’t know the easiest way to write the pixel data to a file. Any suggestions? (I can work in either W32 or Linux).

My ultimate goal is to create a video (e.g. mpeg or avi). I can do this externally from a collection of jpegs, using various programs. It would be cool to be able to encode to an mpeg file within my own program. Is this feasible?



why yes, yes it is. I do it, too. You need to a) work out some way of encoding a bitmap into jpeg (i recommend libjpeg), and b) to copy the framebuffer.

There isn’t much more I can say about it; its just code monkey work. Get libjpeg and work out how to encode a jpeg from a char*, then grab a char* from the screen. easy


John, I believe you were responding to my first question, about writing to a jpeg file. What about the second part (creating a video)?


I’m currently using the libjpeg to save screenshots, and then I use mencoder(see mplayer) under Linux to encode them into a divx video.

This works well, except that saving let’s say 25 jpeg/second slow down quite much my engine. I’ll try to save raw data. Mencoder can read them I think, that would save quite a lot of processing. If that does not work, I’ll try another image format that requires less processing power, like pcx (which still have some compression, to save on disk access).