Drawing without flicker?

This is a discussion on Drawing without flicker? within the Windows Programming forums, part of the Platform Specific Boards category; Hi all, Is it possible to draw several shapes directly on a window during a loop without having any flicker? ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    162

    Unhappy Drawing without flicker?

    Hi all,

    Is it possible to draw several shapes directly on a window during a loop without having any flicker? I have tried to use the ValidateRect and InvalidateRect function, but I canít seem to make them prevent flicker, maybe I am missing something. How do you prevent flicker when drawing directly on a window?
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    The best way is to use a backbuffer. Double-buffering is what its called. Basically you make an offscreen image the same size as the window and you draw unto that. When you're done, you draw that image unto the window. No flicker whatsoever. Its what 2D games use (along with flipping).

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    162
    hehe... yes I know you can use doublebuffering, but I wanto know if it possible to have a flicker-free graphic without it. Thanks anyway
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    162
    Shouldn't it be possible to use ValidateRect or some other function to prevent an graphic area from updating to the screen? So that you can draw stuff to that area and update it when your done, like when you use BeginPaint and EndPaint?
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    The rect should only become invalid if the app calls InvalidateRect() or another window (ect) is passed over the client area.

    Drawing without flicker requires a fast graphics card. Many onboard graphics in new systems are just not fast enough even for simple rendering without flicker.

    Are you using InvalidateRect()? setting the flag (last param) to false (ie don't redraw background?)

    Are you returning true to WM_ERASEBKGND msg's?

    Are you using GetUpdateRect() (before BeginPaint() validates the area) in your paint handler to reduce the area drawn and so increase redraw speed? (look at IsRectEmpty() as well ie exit paint if no area to redraw or redraw whole client area)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Actually, without double buffering (or some other form of drawing that doesn't require an erase/draw procedure), any graphics card will produce flickering regardless of its speed (it just happens less for faster cards) unless the display is updated during the retracing of the monitor... which I hear is going to be possible for the Longhorn OS, as well as no more WM_PAINT messages from other windows erasing your client area, since each window gets its own 'layer', which are all rendering synched to the retrace rate of the monitor, which, as I just said, you should be able to tap into to synchronize your animations... very cool. I have been waiting YEARS for windows to get into hardware acceleration.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing HBITMAP into CWnd, Acquired from "screenshot"
    By DeusAduro in forum Windows Programming
    Replies: 6
    Last Post: 07-02-2009, 04:41 PM
  2. Slow drawing code
    By tjpanda in forum Windows Programming
    Replies: 5
    Last Post: 05-09-2008, 06:09 PM
  3. Line Drawing Algorithm
    By Axpen in forum Game Programming
    Replies: 15
    Last Post: 08-01-2005, 07:30 PM
  4. How to do double buffing with win32 drawing?
    By Josh Kasten in forum Windows Programming
    Replies: 2
    Last Post: 03-27-2004, 12:02 AM
  5. drawing minimaps and radar screens.
    By Eber Kain in forum Game Programming
    Replies: 4
    Last Post: 03-08-2002, 11:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21