hi, i've a problem with flickering. first of all i briefly describe the situation. ok, i've made a program that simulates gas movement in a room. that means, that there are balls moving in the window, bouncing out of the screenborders, and bouncing out of themselves. to draw the balls i first did it with ellipse, but later decided to do it with BitBlt to have the possibility to choose other textures for the balls, that it looks like a football or smth like that. my window background is black. so i made to bitmaps, the first with the ball on it, and a second completly black to erase the old ball that it looks like it is moving. to paint the balls on my window i did smth like that: .elseif uMsg==WM_CREATE invoke LoadBitmap,hInstance,addr bitmapname mov bithandle,eax invoke CreateCompatibleDC,myDC mov bitdc,eax invoke SelectObject,bitdc,bithandle invoke LoadBitmap,hInstance,addr bitmap2name mov bit2handle,eax invoke CreateCompatibleDC,myDC mov bit2dc,eax invoke SelectObject,bit2dc,bit2handle the two bitmaps are now in two different virtual DCs. ok, in the animation loop i used: invoke BitBlt, winhDC, ex1, ey1, ex2, ey2, bit2dc, 0, 0, SRCCOPY to delete the old ball by copying the virtual dc with the black bitmap on my windowdc on the old ball's position. and to show the "real" ball i did the following: invoke BitBlt, winhDC, exnew1, eynew1, ex2, ey2, bitdc, 0, 0, SRCCOPY so in the loop there is deleted the old ball and directly after painted the new. ok. now the problem: to paint the ball i put InvalidateRect to the message loop: StartLoop: invoke GetMessage,ADDR msg,NULL,0,0 cmp eax, 0 je ExitLoop invoke TranslateMessage, ADDR msg invoke DispatchMessage, ADDR msg invoke InvalidateRect,hWnd,NULL,FALSE jmp StartLoop ExitLoop: i used FALSE as the last parameter, so that the whole window ISN'T repainted, and that the window doesnt flicker. but: the balls are flickering. they're flickering a bit, but it is still easy to notice. how can i remove this flickering? i read smth about backbuffering, but i dont want to backbuffer the whole window. please help. tnx
Posted on 2000-12-22 08:31:00 by [SaFc0n]
Hi, in my oppinion, the flickering occurs during the bitblt. Windows doesn't syncronize blits with the vertical blank, so it can be distorted by monitors raster-ray. I think, this is not avoidable under plain windows. Syncronized animation is only possible with DirectX. beaster. (hope, that all of my words are in correct english :)
Posted on 2000-12-22 12:44:00 by beaster
oh yes, it is possible, even without direct x! i've a code example which refreshes its window with, and without flickering. but it backbuffers the whole window. and i've no idea how to backbuffer just a little portion of the window. if someone is interested in this and realy wants to help me, please e-mail me, and i'll send you the whole source.
Posted on 2000-12-22 14:38:00 by [SaFc0n]
c'mon, is there nobody who had this problem and solved it? please help me.
Posted on 2000-12-23 11:08:00 by [SaFc0n]
Hello, perhaps this is a way, I code this and for me it works Performing API InvalidateRect in the Message loop isn't a goog idea. WM_PAINT with API BitBlt is better. What is your animation loop ? I used a third DC. This was my working area used and managed in an extra Thread (multimedia timer 20ms). If work is done I set a flag to allow WM_PAINT in the Main Window Proc. On WM_PAINT I perform BitBlt to update the screen using the working area as the source. Source code is avaible. I do not found a better way ... Test
Posted on 2000-12-24 04:20:00 by Test Department
Whats wrong with back buffering (or double buffering) the whole window? That's the traditional approach to this. It's simple, direct, and it works flicker free. It need not be in a different thread. Just call InvalidateRect when you need a paint, do the ball movement on the private buffer (or if they all move, just repaint ALL the balls on a blank screen). While I wasn't doing moving graphics, I use similar techniques to simulate buttons responding to the mouse. It never flickers.
Posted on 2000-12-24 10:08:00 by Ernie
Hi all, back buffering is OK. But for an animation I think we need a timing. We update the back buffer, OK. Then we perform WM_PAINT, no flicker, OK. If we don't use a timing, updating is not synchron. For example, first WM_PAINT occurs after 30ms and the next after 28 ms, the next after 32ms and so on. Hey Ernie, am I right or not ? so long Test
Posted on 2000-12-25 04:58:00 by Test Department