Advertisement

[Win32] How can I avoir flickering?

Started by July 17, 2001 02:31 PM
3 comments, last by Alload 23 years, 7 months ago
I move lots of images in my Win 32 application, and this makes the scene flicker. Is there a way to avoir flickering? Maybe I could create a back buffer, but I don''t know how to do that with the Win 32 API. Thanks.
hi,

Yeah you are right with double buffer, i will try to explain the methond how tu use it :D

first of all you have your bitmap like these

class cBitmap
{
HBITMAP m_hBitmap; // bitmap handle

// some stuff here to load these bitmap from resource
// or enything else you like to load from
HBITMAP GetBitmap () { return m_hBitmap; }
};

as next you have an Memory Canvas ( our backfuffer ) :

class cMemCanvas
{
HDC m_hDC; // canvas handle

// the given HDC param is your canvas you like to draw
// you bitmap on
cMemCanvas (HDC hDc)
: mHDC (::CreateCompatibleDC (hDC))
{
}
~cMemCanvas ()
{
::DeleteDC (m_hDC); // important if you want memleak free :D
}

VOID cCanvas::SelectObject (VOID *pObject)
{
::SelectObject (m_hDC, pObject);
}
};

so the next one how to blitt on destination Canvas :

HDC MyCanvasToBlitOn;
cBitmap MyBitmapToBlitOnCanvas;

// create memory bitmap
cMemCanvas kMemCanvas (MyCanvasToBlitOn);
// select bitmap to the memory bitmap
kMemCanvas.SelectObject (MyBitmapToBlitOnCanvas.GetBitmap ()); // Important must be the bitmap handle
// blit the memory bitmap
BitBlt (MyCanvasToBlitOn, m_uiXDest, m_uiYDest
m_uiWidth, m_uiHeight,
kMemCanvas, m_uiXSrc, m_uiYSrc, m_uiMode);

hmmm, i think thats all you need, try it :D

Imp

Stay Evil & Ugly!
Advertisement
What''s there to know about doing a buffer? It''s just a normal bitmap sized the size of the screen. You just draw everything on it and draw it on the screen so only you only draw once on the screen every frame. That''s the general idea anyway... (hope you didn''t know that allready making this message totally absolete and putting me into an akward situation )
------------------------------If there be no heaven,may there atleast be a hell.-------------------------------Afterlife-
Using an offscreen bitmap (a buffer) is certainly a great way to avoid flicker using the Win32 GDI. However, it can be very slow. A simple alternative is to mask out the areas you don't need to draw to, then make the changes. So, how's that done? Use the function ExcludeClipRect to define the rectangles where you want to update the screen (I say regions because you can call the functions as many times as you want for any single device context). Then draw the stuff you need to draw. When you're done masking, call SelectClipRgn with NULL as the rectangle to remove all "masks." That's all you have to do, and it's tons faster than an offscreen bitmap.

Edited by - merlin9x9 on July 18, 2001 7:35:41 AM
How can I blit bitmaps to a back buffer bitmap?

This topic is closed to new replies.

Advertisement