Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Alload

[Win32] How can I avoir flickering?

This topic is 6241 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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 )

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!