PDA

View Full Version : printing on monochrome printer



PiotR
03-08-2002, 12:52 AM
I'am using OpenGL under Delphi.
In the help file coming with Delphi I found thery nice description: "how to print OpenGL on monochrome printer". It looks nice but doesn't work.
Generally, I found that wglCreateContext(hdc) returns 0 when hdc is a memory device context (not context of real window).
My code looks like this:
procedure gl_try_to_create_context;
var lpr,cc: HDC;
cRC: HGLRC;
hb: HBITMAP;
ho: HGDIOBJ;
begin
form1.PrintDialog1.execute;
lpr:=CreateDC('WINSPOOL',PChar(Printer.Printers[Printer.PrinterIndex]),nil,nil);
cc:=CreateCompatibleDC(lpr);
hb:=CreateCompatibleBitmap(lpr,printer.pagewidth,p rinter.pageheight);
ho:=selectObject(cc,hb);
gl_SetupPixelFormat(cC);
crc:=wglCreateContext(cc);
if crc>0 then wglMakeCurrent (cc, crc);
end;

procedure gl_setupPixelFormat(ADC:HDC);
const
printer_pfd:TPIXELFORMATDESCRIPTOR =
( nSize:sizeof(TPIXELFORMATDESCRIPTOR);
nVersion:1;
dwFlags:PFD_SUPPORT_OPENGL or PFD_DRAW_TO_BITMAP;
iPixelType:PFD_TYPE_RGBA; cColorBits:8;
cRedBits:0; cRedShift:0;cGreenBits:0;cGreenShift:0;
cBlueBits:0; cBlueShift:0;cAlphaBits:0;cAlphaShift:0;
cAccumBits: 0;cAccumRedBits:0;cAccumGreenBits:0;cAccumBlueBits :0;
cAccumAlphaBits:0;cDepthBits:1;cStencilBits:0;cAux Buffers:0;
iLayerType:PFD_MAIN_PLANE;bReserved:0;dwLayerMask: 0;
dwVisibleMask:0;dwDamageMask:0;
);
var pixelFormat:integer;
begin
pixelFormat := ChoosePixelFormat(ADC, @printer_pfd);
if (pixelFormat = 0) then exit;
if (SetPixelFormat(ADC, pixelFormat, @printer_pfd) <> TRUE) then
exit;
end;

Is there any other way to do it?