younthu

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

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(00, rt.Width(), rt.Height(), &m_dcMemory, 00, SRCCOPY);

 

refered to :http://www.vckbase.com/document/viewdoc/?id=1612

 

 

posted on 2009-11-09 11:39  younthu  阅读(317)  评论(0编辑  收藏  举报

导航