CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Guest

    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!


  2. #2
    Join Date
    May 1999
    Posts
    67

    Use ROP codes, memory device context or directx

    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




  3. #3
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939

    Re: reduction of flicker

    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
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

  4. #4
    Join Date
    Jun 1999
    Posts
    5

    Re: reduction of flicker

    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


  5. #5
    Guest

    Re: reduction of flicker

    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)
    .....



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured