Has anyone out there had any luck at printing using OpenGl and
MFC? If so would you kindly assist me in attempting the same.
This is an urgent requirement, so I would be very grateful for
any assistence offered.
Martin J. Bysh
I've just written the code for the printing module of a CAD software usingQuote:>Has anyone out there had any luck at printing using OpenGl and
>MFC? If so would you kindly assist me in attempting the same.
First of all, I've never succeded in using the metafile technique described
in Microsoft's documentation...
I do the rendering into a DIB section attached to a memory device context
(with the PFD_DRAW_TO_BITMAP flag for SetPixelFormat()). I use a 24-bpp DIB
for it gives the best results.
The problem is that the resolution of a printer is far superior to that of a
screen. With 600 dpi, you would need hundreds of millions of pixels, which
is just too much for OpenGL (i.e. wglCreateContext() will fail).
So I cut the rendering into stripes with a height such that width *
stripe_height < 1 million (for example).
For each stripe, set the partial viewport with glViewport() and the partial
window with glOrtho() / glFrustum(), and render the scene (with a good view
culling, it's not too costly). Then blt the DIB at the good place into the
printer device context using StretchBlt(). The printer driver will handle
I've tested this method on a black&white HP laser printer and on a color
inkjet printer, and it works fine. Good luck!
I am attempting to print my scene using OpenGL and the MFC. In the Windows
help, I found a reference to Printing an OpenGL Image, which infoms me that
I have to create a metafile DC, set this as the rendering context using
wglCreateContext, then render with OpenGL, and that's that. However, I
cannot get any of this to work. Whatever I have tried, the HGLRC passed
back from wglCreateContext is always NULL.
Has anyone acheived printing using OpenGL and the MFC (or simply just OpenGL
and Win32). If so, could you please give me some idea of what to do, or
perhaps some sample source code.
Any help would be appreciated.