Why can't i write to a memory device context?

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);
}

You must use PFD_DRAW_TO_BITMAP in the dwFlags field if you want to render with OpenGL to a memory device context.
If you do that, you will choose the Microsoft GDI Generic OpenGL implementation because only that supports rendering to memory bitmaps.
Means your main window will probably run with a different OpenGL implementation than your memory device. No sharing of OpenGL data and no advanced OpenGL features beyond version 1.1 will be possible on the memory device.

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.
What flicker? “Crazy” is not a sufficient error description.
The usual beginner’s OpenGL “flicker” problem is that you must implement a handler for the WM_ERASEBKGND message which just returns non-zero to keep GDI from clearing the window background with the window’s default workspace color before WM_PAINT messages are handled.
There must be no flicker when rendering double buffered OpenGL and you should dump the whole idea of the memory bitmap in favor of offscreen surfaces like pbuffers or framebuffer objects if you need that at all.

I have read an article on msdn saying how to write to a bitmap but it is too complex and inconvenient.
The Win32 API is just like that. :frowning:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.