printing textured triangles C, win32

Started by
4 comments, last by szecs 12 years, 8 months ago
I would like to print textured triangles with a printer.
It's easy to print other primitives like lines with GDI, but I haven't found a way to print textured triangles. GDI+ can do that (although it seems quite tedious) but I code in C.

Maybe I could use directx for that, but I code in openGL....

Or I could make my own software rasteriser and draw the triangles pixel-by-pixel. (which may be unnecessary, and would be slow with A4 or A3 and 600 dpi I guess).

Or I could even render to an openGL texture then use that (or glReadPixels). Which again seems iffy with that big resolution (this is my best bet so far)


Do I have other choices than these? Maybe I've missed something simple, I couldn't find much with Google.

Thanks for any hints in advance!
Advertisement
Try Printing an OpenGL Image, if it suits your needs.
Thank you.
I cannot comprehend the MSDN documentations.

The following code produces a 0 byte metafile and of course nothing is printed. (Prints regular GDI stuff just fine).

[source lang=CPP]void RenderToPrinter(int w,int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w,0,h,-5000,5000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0,0,w,h);

glColor4f(1,0,0,1);

glBegin(GL_LINE_LOOP);//GL_TRIANGLES);

glVertex2i(10,10);
glVertex2i(20,100);
glVertex2i(100,50);

glEnd();

glFlush();
}

...
StartDoc (hDC, &di);
StartPage(hDC);

// metafile fucking //

RECT rect;
HDC hdcMeta;
HGLRC hglrc;

rect.left = 0;
rect.right = width_px/hDpmm*100.0; // Dpmm = Dots per mm
rect.top = 0;
rect.bottom = height_px/vDpmm*100.0;

hdcMeta = CreateEnhMetaFile(hDC,"temp_print.emf",
&rect, "paper_modeller_V2\0print temp\0\0");

if( hdcMeta == NULL )
{
MessageBox(MainWindow.hWnd,"kurva anyád","gecikurva anyád",MB_OK);
}

hglrc = wglCreateContext ( hdcMeta );

if( hglrc == NULL )
{
MessageBox(MainWindow.hWnd,"kurva anyád","gecikurva anyád",MB_OK);
}

wglMakeCurrent(hdcMeta,hglrc);


RenderToPrinter(rect.right,rect.bottom);

HENHMETAFILE fasz;
fasz = GetEnhMetaFile("temp_print.emf");

PlayEnhMetaFile(hDC,fasz,&rect);


wglMakeCurrent(MainWindow.hDC, MainWindow.hRC);

/*HENHMETAFILE fasz;
fasz = GetEnhMetaFile("temp_print.emf");

PlayEnhMetaFile(hDC,fasz,&rect);*/
....

EndPage(hDC);
EndDoc(hDC);
[/source]
Hmm, why the EMF in there? Simply doing anything to hDC should end up on the printer.

This function gets a HDC for a printer. Just use it like you do in your example.


HDC CBelegPrinter::CreateHandleForDC( const char* printerName )
{

HANDLE hPrinter;

if ( ( ::OpenPrinter( const_cast<TCHAR*>( printerName ), &hPrinter, NULL ) ) )
{
LPPRINTER_INFO_2 lpPrinterInfo2 = NULL;
DWORD sizeOfPrintInfo = 0;
DWORD cbReturned = 0;

::GetPrinter( hPrinter, 2, NULL, 0, &sizeOfPrintInfo );

lpPrinterInfo2 = (LPPRINTER_INFO_2)new char[sizeOfPrintInfo];

if ( ::GetPrinter( hPrinter, // handle to printer
2, // information level
(LPBYTE)lpPrinterInfo2, // printer information buffer
sizeOfPrintInfo, // size of buffer
&cbReturned ) ) // bytes received or required
{
m_hDC = ::CreateDC( lpPrinterInfo2->pDriverName,
lpPrinterInfo2->pPrinterName,
NULL,
lpPrinterInfo2->pDevMode );
}

delete[] lpPrinterInfo2;
lpPrinterInfo2=NULL;

ClosePrinter( hPrinter );
}
return m_hDC;

}


Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Thanks, I was thinking about the simple DC thing, but need good resolution prints, even with A3 printers.
(And I've read it's not that simple to do it directly to the printer, but you can do it in a memory DC then blit that).

Maybe I shouldn't worry about the memory, because 270 MB is not that big (for A3 with 600 DPI). Or maybe I shouldn't worry about the resolution (well, I guess I should...).

This topic is closed to new replies.

Advertisement