|
Wednesday, July 19, 2006
Wow.
The last time I worked on an app which used 3D graphics,
printing was fairly simple. OpenGL was brand new and DirectX didn't exist yet,
so we had to do all the projection math anyway. Adapting the code from screen
to paper wasn't a big deal.
Modern graphics APIs are great, but they don't help with
printing. Since I started my woodworking app using C# and Direct3D, I always
figured it would be a huge task to implement printing. More to the point,
since this app is a hobby project and the implementation of printing would
probably be like real work, I figured this app would never be able to
print.
Recently I switched everything over to WPF. Here is my
printing code:
PrintDialog dlg = new PrintDialog();
if ((bool)dlg.ShowDialog().GetValueOrDefault())
{
dlg.PrintVisual(myViewport, "sawdust");
}
Five lines. Were it not for my pathological need to use
braces on every if statement, it would be three lines.
Yes, yes I know -- a useful real-world printing feature
would require more work. I'm just saying: I added these five lines to my app
and a color picture of my bookshelf model emerged out of the printer down the
hall. That's excellent.
|