From ObjReader, to print the OpenGL display...
// 05-22-2015
long SendToPrinter() {
long nRet = 0;
RECT rc = { 0 };
GetWindowRect(gP.hMain, &rc);
long Wdth = ((rc.right - rc.left) - 438) / 2 - 48;
long Hght = ((rc.bottom - rc.top) - 314) / 2 - 52;
long X = rc.left + Wdth;
long Y = rc.top + Hght;
HWND hTmp = CreateWindowEx(0, L"STATIC", $NULL, WS_POPUP, X, Y, 0, 0, gP.hMain, 0, gP.hInstance, NULL);
// Setup the print common dialog
PRINTDLG pd;
pd.lStructSize = sizeof(pd);
pd.hwndOwner = hTmp;
pd.hDevMode = NULL;
pd.hDevNames = NULL;
pd.nFromPage = 0;
pd.nToPage = 0;
pd.nMinPage = 0;
pd.nMaxPage = 0;
pd.nCopies = 0;
pd.hInstance = gP.hInstance;
pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_PRINTSETUP;
pd.lpfnSetupHook = NULL;
pd.lpSetupTemplateName = NULL;
pd.lpfnPrintHook = NULL;
pd.lpPrintTemplateName = NULL;
if (PrintDlg(&pd)) {
long hSize = GetDeviceCaps(pd.hDC, HORZSIZE);
long vSize = GetDeviceCaps(pd.hDC, VERTSIZE);
long hRes = GetDeviceCaps(pd.hDC, HORZRES);
long vRes = GetDeviceCaps(pd.hDC, VERTRES);
WCHAR PathName[MAX_PATH] = { 0 };
WCHAR FilName[MAX_PATH] = { 0 };
zSplitN(zExeName(), &PathName[0], &FilName[0]);
Add_Str(FilName, L"_output");
DOCINFO dinfo;
dinfo.cbSize = sizeof(dinfo);
dinfo.lpszDocName = &FilName[0];
dinfo.lpszOutput = NULL;
// Detect printer orientation mode
long Landscape = -1; if (vSize > hSize) { Landscape = 0; }
// Compute the printing size
long offsetX, offsetY;
if (Landscape) {
offsetX = 60; offsetY = 0;
} else {
offsetX = 15; offsetY = 60;
}
LONG_PTR img = 0;
GetClientRect(gP.hGL, &rc);
// 07-17-2017 respect boundary alignment
rc.right = (rc.right / 4) * 4;
rc.bottom = (rc.bottom / 4) * 4;
BYTE* buffer = new BYTE[rc.right * rc.bottom * 3];
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, rc.right, rc.bottom, GL_BGR, GL_UNSIGNED_BYTE, &buffer[0]);
if (GdipCreateBitmapFromScan0(rc.right, rc.bottom, rc.right * 3, PixelFormat24bppRGB, &buffer[0], img) == 0) {
if (img) {
if (GdipImageRotateFlip(img, 6) == 0) {
HBITMAP hPrintBitmap = 0; long background = 0;
if (GdipCreateHBITMAPFromBitmap(img, hPrintBitmap, background) == 0) {
float rCoef = min((float)((hRes - (offsetX * 2)) / (float)rc.right), (float)((vRes - (offsetY * 2)) / (float)rc.bottom));
long fxSize = (long)(rc.right * rCoef);
long fySize = (long)(rc.bottom * rCoef);
long xTop = (hRes - fxSize) / 2 + offsetX;
long yTop = (vRes - fySize) / 2 + offsetY;
if (StartDoc(pd.hDC, &dinfo) > 0) {
if (StartPage(pd.hDC) > 0) {
// Paint the DIB bitmap
PrintBitmap(hPrintBitmap, pd.hDC, xTop, yTop, fxSize, fySize);
nRet = EndPage(pd.hDC);
if (nRet > 0) {
nRet = -1;
EndDoc(pd.hDC);
} else {
nRet = 0;
}
}
}
DeleteObject(hPrintBitmap);
}
}
GdipDisposeImage(img);
}
}
delete[] buffer;
DeleteDC(pd.hDC);
}
DestroyWindow(hTmp);
return nRet;
}
See the attachment of my current Work In Progress, that 3D model should be completed soon.
I have to add some more stickers, extra ambient occlusion, lighting, and ground shadow…