View Full Version : OpenGL to PDF
Hi all,
I have a Carbon game that uses OpenGL for all rendering. I'd like to be able to print screenshots, with various options, and I figure the easiest way to do that would be:
- generate a PDF,
- open the PDF in Preview (thereby letting the user set their print options, save, etc.)
How would I go about doing these two tasks?
thanks.
OneSadCookie
2006.08.18, 03:49 AM
I recommend generating a bitmap image format instead.
* Use glReadPixels to read the image back from the screen, into a
* CGBitmapContext or NSBitmapImageRep of your own construction, then
* Use ImageIO or Cocoa's built-in image saving functionality to produce a
* PNG or in the worst case, a TIFF.
Thanks for the help. As I'm using a Carbon app, how could I then take the PNG (or tiff) and have it opened automagically in Preview?
Oh, I should point out that I'm backward compatible to 10.2, so ImageIO would seem to be out.
OneSadCookie
2006.08.18, 05:08 AM
You'll need to use QuickTime's GraphicsExport then probably, or you could use libpng "by hand".
LaunchServices will open the picture in another application for you.
ThemsAllTook
2006.08.18, 10:06 AM
You'll need to use QuickTime's GraphicsExport then probably,
The QuickTime C API is being deprecated in Leopard, isn't it? Other options might be more future-proof.
OneSadCookie
2006.08.18, 08:12 PM
My understanding is that it's not deprecated, just not available for 64-bit applications.
If he has to go back to 10.2 in Carbon, it's pretty much either GraphicsExport or an open-source library like libpng, with a second path for 64-bit on Leopard if he ever wants to build for that.
ThemsAllTook
2006.08.18, 08:52 PM
Ah yes, that's right. Whew, now I won't have to worry so much about my own use of QuickTime...
erwincoumans
2006.08.27, 06:06 PM
Perhaps you want to checkout gl2ps, it has an option to export to pdf too:
Unfortunately it doesn't support textures, but perhaps you might find the vector output useful.
http://www.geuz.org/gl2ps/
skyhawk
2006.09.08, 08:50 PM
In a similar notion to this, I have a window with many buttons in it, including an OpenGL context in it. What would be the best way to print this window?
skyhawk
2006.10.06, 05:30 PM
In a similar notion to this, I have a window with many buttons in it, including an OpenGL context in it. What would be the best way to print this window?
the answer I came up with:
[[NSApp mainWindow] print:NULL];
OneSadCookie
2006.10.06, 09:15 PM
Should be
[[NSApp mainWindow] print:nil];
:p
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.