Thread: Animation without tearing

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    330

    Animation without tearing

    Hi

    I have an MFC dialogbox application where I draw bitmaps after each other making it look like a movie. But the image tears sometimes. Is there a way to make it look better?

    This is current code:

    Code:
    CPaintDC dc(this);
    CDC hdcmem;
    
    hdcmem.CreateCompatibleDC(NULL);
    CGdiObject *old = hdcmem.SelectObject(&m_bitmap);
    
    dc.StretchBlt(STARTXSTATIC + m_size.cx + 10, STARTYSTATIC, 
    	  m_size.cx, m_size.cy / m_nofimages, 
    	  &hdcmem, 0, m_curanim * (m_size.cy / m_nofimages), m_size.cx,
    	  m_size.cy / m_nofimages, SRCCOPY);
    
    hdcmem.SelectObject(old);

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Double Buffering. Draw it all to a back buffer then blast it at once to screen, that should stop tearing.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    It appears as if he is already double buffering from hdcmem to the paint DC of the window. Have you turned off the windows default provided double buffering scheme for your window? Sometimes that will get in the way of a refresh and/or cause images to fail to display or display incorrectly. I forget which call in MFC does this so you will have to research it.

  4. #4
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    you mean WM_ERASEBKGND? That caused a lot of other problems
    I solved it by removing the Invalidate from the OnTimer and calling the DrawFrame function directly from the timerevent. That solved it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Threads in MFC
    By VirtualAce in forum Windows Programming
    Replies: 4
    Last Post: 12-28-2005, 06:03 PM
  2. Animation class not working
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 03-02-2005, 06:48 AM
  3. Animation not working....
    By aquinn in forum C Programming
    Replies: 7
    Last Post: 02-19-2005, 05:37 AM
  4. animation timing
    By Eber Kain in forum Game Programming
    Replies: 2
    Last Post: 06-29-2004, 06:32 PM
  5. 3D animation (difficult?)
    By maes in forum Game Programming
    Replies: 3
    Last Post: 09-08-2003, 10:44 PM