I wish to use opengl to write to a memory device context then use bitblt() to avoid flicker, but the result returns out to be crazy. I have read an article on msdn saying how to write to a bitmap but it is too complex and inconvenient.
Is there any easier way out? Thanks.
Heres some code:
inline bool wglForSDI::CreateRaw(CView* pViewWnd)
{
static PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,0,0,
0,0,0,0,0,
32,
0,0,
PFD_MAIN_PLANE,
0,
0,0,0,
};
m_pViewWnd = pViewWnd;
HDC hdc = pViewWnd->GetDC()->GetSafeHdc();
int nPixelFormat;
if ((nPixelFormat = ::ChoosePixelFormat(hdc, &pfd)) == 0) return false;
if(::SetPixelFormat(hdc, nPixelFormat, &pfd) == FALSE) return false;
m_memDC.CreateCompatibleDC(pViewWnd->GetDC());
m_buf.CreateCompatibleBitmap(pViewWnd->GetDC(), 2048, 1536);
m_memDC.SelectObject(&m_buf);
if ((nPixelFormat = ::ChoosePixelFormat(m_memDC.m_hDC, &pfd)) == 0) return false;
if(::SetPixelFormat(m_memDC.m_hDC, nPixelFormat, &pfd) == FALSE) return false;
if ((m_hrc = ::wglCreateContext(m_memDC.m_hDC)) == NULL) return false;
if (::wglMakeCurrent(m_memDC.m_hDC, m_hrc) == FALSE) return false;
return true;
}
inline void wglForSDI::PrintDC()
{
RECT r;
m_pViewWnd->GetClientRect(&r);
int w = r.right - r.left;
int h = r.bottom - r.top;
::glFinish();
::SwapBuffers(::wglGetCurrentDC());
m_pViewWnd->GetDC()->BitBlt(0, 0, w, h, &m_memDC, 0, 0, SRCCOPY);
}