Click to See Complete Forum and Search --> : reduction of flicker
Hello,
I have a program that displays the output of a sensor device in real time. It uses normal GDI calls to display a line plot of the incoming data. It works fine, but there is a great deal of flicker in the image as it is being updated. What is the best way to reduce this flicker (I guess my real question is how does one do graphical output when the graph is changing rapidly, like in a data acquisition application)? Should I be using OpenGL or something?
Thanks!
Roland Seibert
June 8th, 1999, 12:30 AM
To prevent flicker, don't erase background. This means don't use InvalidateRect(..,TRUE). If only the graph (dataline) is changing (i mean only data and not the axis scaling or something else) you can use rop codes to draw the old line and then the new one.
A second method is to draw into a memory device context and then blit it to screen.
If all these methods are too slow you can use directx.
Hope this helps
Roger Allen
June 8th, 1999, 03:44 AM
Try this code for BitBlting:
{
// I personally have never liked using CPaintDC
CPaintDC dc(this); // device context for painting
}
CDC* pDC ;
CDC compatDC ;
CBitmap compatBitmap ;
CRect rect ;
GetWindowRect(&rect) ;
// you may need to do ScreenToClient() on rect
pDC = GetDC() ;
// draw to a compatible device context and then bitblt to screen
compatDC.CreateCompatibleDC(pDC) ;
compatDC.SaveDC() ;
compatBitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()) ;
compatDC.SelectObject(&compatBitmap) ;
// do your drawing code here to compatDC
// note that your drawing code has to be indexed from 0,0 to rect.Width(), rect.Height()
// bitblt the buffered graph to the display
pDC->BitBlt(rect.left,
rect.top,
rect.Width(),
rect.Height(),
&compatDC,
0,
0,
SRCCOPY) ;
compatDC.RestoreDC(-1) ;
compatBitmap.DeleteObject() ;
compatDC.DeleteDC() ;
ReleaseDC(pDC) ;
HTH
Roger Allen
LeChat
June 8th, 1999, 04:53 AM
I've written such type of real time application. Remember this is not necessary to update the screen more than 20 or 25 times per seconds because the human eye can not see it. Using a memory DC and a transparent background (no background) is fast enough and there is no flicker at all.
Using DirectX is more powerfull. You will never see a partial bitmap on the screen and the drawing is faster. But it is more difficult to use.
Laurent Guinnard
To absolutely prevent flicker you can access the video memory only during the vertical blanking pulse (when the beam is moving back to the top of the screen to prepare for another frame). Try this...
LPDIRECTDRAW lpDD;
VERIFY(DirectDrawCreate(NULL, &lpDD, NULL));
.......
//get ready to draw (get a DC etc).
IDirectDraw2_WaitForVerticalBlank(lpDD,DDWAITVB_BLOCKBEGIN, 0);
//Draw NOW!!! (must be able to complete rendering in short period of time)
.....
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.