-
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? :(
-
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).
-
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 ;)
-
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?
-
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)
-
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.