I have in my game some code to use an offscreen device context (buffer) to elimate bitmap flickering in my game as everything is redrawn each cycle. The code is taken from source code included with a book, and i've seen it work before. But for some reason, I still get flickering in the game i'm creating myself.
These are delarations in my header file:
HDC _hOffscreenDC;
HBITMAP _hOffscreenBitmap;
This is my GameCycle() function:
void GameCycle()
{
if (!_bGameOver)
{
// Update the sprites
_pGame->UpdateSprites();
// Obtain a device context for repainting the game
HWND hWindow = _pGame->GetWindow();
HDC hDC = GetDC(hWindow);
// Paint the game to the offscreen device context
GamePaint(_hOffscreenDC);
// Blit the offscreen bitmap to the game screen
BitBlt(hDC, 0, 0, _pGame->GetWidth(), _pGame->GetHeight(),
_hOffscreenDC, 0, 0, SRCCOPY);
// Force a repaint to redraw the sprites
InvalidateRect(_pGame->GetWindow(), NULL, FALSE);
// Cleanup
ReleaseDC(hWindow, hDC);
}
}
Can anybody suggest what I should do if this isn't eliminating flickering?
Also, I feel I should point out that I get no errors. It compiles and runs without a hitch. I just don't see the buffer working the way I guess I think it should.