Framebuffer to JPG
The Steps
Get the Header File
Use #include on it
Set WIDTH and HEIGHT
Attach get_rgb() and outputp3("image.ppm") to a keyboard shortcut
convert -flip image.ppm image.jpg
In More Detail:
First, get the header file. This is really just code, but I use
it as a header for simplicity. It is available as output.h
Now that you have the header
file, be sure to include it in the file that has your keyboard
commands. For simplicity, I'll call it "main.cpp"
Now you need to
edit output.h such that RAMSEY_WIDTH and RAMSEY_HEIGHT are the width and height of
your window
I usually attach the screen dump to a
keyboard shortcut. So, let's say the user presses the '1' key. When
they do, I execute the following function calls from output.h. First,
get_rgb(). This will get the framebuffer into a simple unsigned
character array called rgb. You could call get_rgb() at the end of your display function as well. You can see it declared in output.h. Next,
I call outputp3("image.ppm"). You can pass any string to outputp3 and
it will try to write a file of that name. You should use the extension
ppm since the file is technically a ppm file.
Now you have an image file which contains your framebuffer. The only problem is that it is likely upside down (although you could certainly modify the for loop to correct this) AND not many programs read ppms. On albert (or many linux boxes really), you can execute the following command to fix that problem: convert -flip image.ppm image.jpg
At this point you have an image.jpg which is an exact screenshot of your program when you pressed the '1' key.