Hi,
We have to give the OpenGL scene rendered at that time in a PDF format for future use. For that we drawn the scene Bitmap and then taken the PDF format using Print command. But the resolution is very low while zooming in. The PDF format diagram itself become very blurred. Please help in this.
Following is the code:
CRect rcClient;
pView-> GetClientRect(&rcClient);
float fClientRatio = float(rcClient.Height())/rcClient.Width();
// Get page size
m_szPage.cx = pDC->GetDeviceCaps(HORZRES);
m_szPage.cy = pDC->GetDeviceCaps(VERTRES);
CSize szDIB;
if (pInfo-> m_bPreview)
{
// Use screen resolution for preview.
szDIB.cx = rcClient.Width();
szDIB.cy = rcClient.Height();
}
else // Printing
{
// Use higher resolution for printing.
// Adjust size according screen's ratio.
if (m_szPage.cy > fClientRatio*m_szPage.cx)
{
// View area is wider than Printer area
szDIB.cx = m_szPage.cx;
szDIB.cy = long(fClientRatio*m_szPage.cx);
}
else
{
// View area is narrower than Printer area
szDIB.cx = long(float(m_szPage.cy)/fClientRatio);
szDIB.cy = m_szPage.cy;
}
// Reduce the Resolution if the Bitmap size is too big.
// Ajdust the maximum value, which is depends on printer's memory.
// I use 20 MB.
while (szDIB.cx*szDIB.cy > 30e6)
{
szDIB.cx = szDIB.cx / 2;
szDIB.cy = szDIB.cy / 2;
}
}
TRACE("Buffer size: %d x %d = %6.2f MB
", szDIB.cx, szDIB.cy, szDIB.cxszDIB.cy0.000001);
// 2. Create DIB Section
memset(&m_bmi, 0, sizeof(BITMAPINFO));
m_bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
m_bmi.bmiHeader.biWidth = szDIB.cx;
m_bmi.bmiHeader.biHeight = szDIB.cy;
m_bmi.bmiHeader.biPlanes = 1;
m_bmi.bmiHeader.biBitCount = 24;
m_bmi.bmiHeader.biCompression = BI_RGB;
m_bmi.bmiHeader.biSizeImage = szDIB.cx * szDIB.cy * 3;
HDC hDC = ::GetDC(pView -> m_hWnd);
m_hDib = ::CreateDIBSection(hDC, &m_bmi, DIB_RGB_COLORS, &m_pBitmapBits, NULL, (DWORD)0);
::ReleaseDC(pView -> m_hWnd, hDC);
/***************/
// 3. Create memory DC, and associate it with the DIB.
m_hMemDC = ::CreateCompatibleDC(NULL);
if (!m_hMemDC)
{
DeleteObject(m_hDib);
m_hDib = NULL;
return;
}
SelectObject(m_hMemDC, m_hDib);
// 4. Setup memory DC's pixel format.
if (!SetDCPixelFormat(m_hMemDC, PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_STEREO_DONTCARE))
{
DeleteObject(m_hDib);
m_hDib = NULL;
DeleteDC(m_hMemDC);
m_hMemDC = NULL;
return;
}
// 5. Create memory RC
m_hMemRC = ::wglCreateContext(m_hMemDC);
if (!m_hMemRC)
{
DeleteObject(m_hDib);
m_hDib = NULL;
DeleteDC(m_hMemDC);
m_hMemDC = NULL;
return;
}
// 6. Store old DC and RC
m_hOldDC = ::wglGetCurrentDC();
m_hOldRC = ::wglGetCurrentContext();
// 7. Make the memory RC current
::wglMakeCurrent(m_hMemDC, m_hMemRC);
// 8. Set OpenGL state for memory RC.
// The state is the same as the screen RC's.
// SetOpenGLState();
::glViewport(0, 0, szDIB.cx, szDIB.cy);
SetFrustum();
// 9. Create display list with the newly created memory RC
Draw();
CreateDisplayList();
///////////////////////////////////
void CDocumentationView::CreateDisplayList(UINT nList)
{
::glNewList(1, GL_COMPILE);
Draw();
::glEndList();
}
Please help to solve it.