double-buffer of GDI
GDI is not a good choice for Game development for its efficiency. But for some simple 2D game, GDI is enough.
The biggest problem for game dev in GDI is screen blink. if we draw picture/graphic figure in screen directly, the figures will be draw out step by step. if there are too many graphic figures or the drawing is implemented frequently, the screen will blink.
Is there a way to solve this problem? yes, double-buffer will help you.
To implement doubl-buffer in GDI, you can follow these steps:
1)Create a compatible
if(!m_dcMemory.CreateCompatibleDC(NULL)) // CDC m_dcMemory;
{
::PostQuitMessage(0);
}
{
::PostQuitMessage(0);
}
2)CreateCompatibleBitmap
m_Bmp.CreateCompatibleBitmap(&m_dcMemory, rt.Width(), rt.Height()); // CBitmap m_Bmp;
3)Select Bitmap into dc
::SelectObject(m_dcMemory.GetSafeHdc(), m_Bmp);
4) Copy the bitmap to screen
pdcView->BitBlt(0, 0, rt.Width(), rt.Height(), &m_dcMemory, 0, 0, SRCCOPY);
refered to :http://www.vckbase.com/document/viewdoc/?id=1612
浙公网安备 33010602011771号