double-buffer of GDI

本文讨论了使用GDI进行游戏开发时遇到的屏幕闪烁问题,并提供了一种解决方案——双缓冲技术。通过创建兼容设备环境、位图,选择位图到设备环境,最后将位图复制到屏幕上,可以有效避免屏幕闪烁。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 

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

 

 

转载于:https://www.cnblogs.com/younthu/archive/2009/11/09/1598914.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值