10/25/02: Progress Report #3

Plan

The screenshot program of the last iteration is completely useless to my techlab project unless applied to my old museum code, so that's the goal of this third iteration.  I have the suspicion that SDL is not needed at all for the screenshot function to work, so I'm going to try and take the screenshot function out of the SDL code and insert it into the actual museum code.  However, I expect to encounter some nasty complications with the keyboard function.  The sample program of the second iteration had no user interaction.  The the virtual museum code does--it must, in order to move around, otherwise there's no point to having an animated gif.  Therefore, the success of this iteration will be determined by whether or not I can produce an animated gif of a user moving around the museum.  Again, it would be nice to continue perusing OpenGL tutorials and taping history video clips while I'm working on this program, but again, it's not top priority.

Design

As I mentioned earlier, I suspected that the SDL program is not even needed, so I'm tried to just copy the char *number(int num) function (which converts integers to arrays of characters) and the int screenShot(const char *filename) function (which saves the screen output as a targa file) into the virtual museum program.  To my great surprise, this worked after I smoothed out a couple of bugs, but this by no means meant that the whole program actually worked.  But I'm getting ahead of myself.  I had to do a little modifying in the whole taking screenshots thing because in the other program, it just ran until it hit one hundred frames and then it stopped running.  I couldn't very well do the same thing with the museum.  If the program stopped running after one hundred keystrokes, the user wouldn't even have been to reach the first exhibit.  Therefore, I modified the code so that it stopped taking screengrabs after one hundred pictures.  I called the screenshot function in int main() after the display function and before the mainloop call--like it was in the SDL program code.

So I run the program again, and it's running along, happy as a clam.  However, as soon as I hit a key on the keyboard the text output I had coded into the program for debugging purpose went nuts.  Normally, it gave me the filename that it was writing the image to, but suddenly, it was outputting nothing.  When I checked my directories for the targa files, there was nothing there.  As I predicted, user interaction messed up the screengrabbing.  I spent a while modifying the screenshot function until I had moved all the filewriting directly into the function.  so instead of sending the filename to the screenshot function as a parameter, the screenshot function took no parameter and merely figured out the name of the file it would save the tga to within the function.  However, the problem turned out not to be between the screenshot function and the keyboard function, but rather between the creation of the array of characters that would be the filename of the targa file and the keyboard function.  Something about the user hitting keys on the keyboard was messing up the strcat function.  I managed to solve the bug by eliminating the use of the strcat function.

However, there was one last problem that needed solving.  Now, the program was outputting a filename, which was encouraging, but for some reason, it kept the filename contained a nonsense character at the end that prevented the file from being an image file.  For example, instead of being named "000.tga," the filename would be "000.tga@."  I finally realized that the reason was that I was forgetting to set the last character of the character array to "0" (not the character "0," the integer "0") to signify the end of the filename.  After that, everything was peachy.

Coding

Download the code for this iteration: report03-museum.cpp

As I said and as you can see, I combined the screenshot program and the museum program into one.  However, you will still need the tgatogif Perl script and the whirlgif program to make the convert the tga's into gif's and the gif's into animated gif's.  A small note, however: when calling the whirlgif program, you need to add in the parameter -globmap before -o outputfile.gif otherwise it'll blow up on you.

Testing

As in the second iteration, testing this iteration was very easy.  It's a question of whether or not I have an animated gif to show, and here it is: