10/04/02: Progress Report #2

Plan

The goal of this iteration is to produce a function--or even a program--that will take the computer output to the screen and save it as a series of pictures.  These pictures can then be converted to gif files and combined into an animated gif.  There does not seem to be a simple built-in OpenGL function that takes screengrabs, so this iteration of the program will include coding.  Ideally, I will continue reading OpenGL tutorials, but that is not high on my priorities list.

The expected outcome of this project is a function or program that saves the OpenGL output as a picture each frame.  The screengrab can be any picture file because it will then be converted to a gif file, and the gif files will be combined into a single animated gif that I can post on the website to show my progress.

Design

With a little bit of research, and a lot of help from friend, I decided to use SDL's (Simple DirectMedia Layer) SDL_SaveBMP function to try and save a screenshot.  Borrowing basic SDL code from NeHe, we modified it to save the first one hundred frames as "000.bmp" to "099.bmp." This involved writing our own function that converted integers to arrays of characters.  However, the SDL_SaveBMP function wouldn't work, so we found another function on the Internet that saved screenshots as targa (tga) files.  You can find the site where we borrowed this code in my Technical Links page.  We added this screenshot function to the SDL program code, and it worked.

The other obstacle I had to overcome was first of all, converting the tga files in to gif file's, and after that, combining them all into one animated gif.  This process proved to be as time-consuming as writing and modifying the code for taking screenshots had been.  Another friend of mine had to teach me basic Perl scripts to convert the tga's into gif's.  This involved nothing more than two nested for-loops, but the convert program was slow, and converting one hundred files took a while.  However, the animated gif was finally created, and even though I really didn't get a chance to read anymore OpenGL tutorials during this iteration, I was introduced to two new languages, so I consider this iteration a success.

Coding

Download the code for this iteration: report02-leapfrog.cpp, report02-sdl.cpp, and report02-tgatogif.

'report02-leapfrog.cpp' is the sample program that I'm taking screenshots of; 'report02-sdl.cpp' is the SDL program that takes the pictures in the form of tga files.  It contains the screenshot function, and 'report02-leapfrog.cpp' is an include file of it.  Finally, 'report02-tgatogif' is the Perl script that converts targa files '000.tga' to '100.tga' into gif files.  The last program that I used was whirlgif.  I had saved all my image files into one directory, so in order to make an animated gif, all I had to do was type in the terminal: whirlgif -o outputfilename.gif -loop *.gif. The -loop parameter makes the animated gif loop infinitely, and the program just puts the gifs into one gif in alphabetical (or numerical) order.  Now, I have an animated gif named outputfilename.gif.

Testing

Testing whether this iteration is successful is pretty straightforward and easy.  Do I have an animated gif to show for all that coding?  And look at that!  I do: