c++ gdi+ double buffer problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ramilol
    New Member
    • Aug 2010
    • 14

    c++ gdi+ double buffer problem

    ok i have no idea how double buffer works
    i really need good sample example or tutorial
    thanks
    Ramiz
  • Joseph Martell
    Recognized Expert New Member
    • Jan 2010
    • 198

    #2
    Gdi+ doesn't have a "double buffer" setting so you have to do it manually (as far as I know).

    Basically, you create an image (Gdiplus::Bitma p) the size of the window's client area (or whatever size you want) to act as your buffer. Then create a Gdiplus::Graphi cs object using the buffer image as a parameter for the constructor. Draw everything using the buffer Graphics object. After all of your drawing is done you draw your buffer image to the window's active graphics object.

    Comment

    • ramilol
      New Member
      • Aug 2010
      • 14

      #3
      can you give me an simple example with code

      Comment

      • Joseph Martell
        Recognized Expert New Member
        • Jan 2010
        • 198

        #4
        here is a snippet of code that I used in a program I wrote a while ago:

        Code:
        //get the rectangle of the active window
        RECT clientRec;
        GetClientRect(_platformInfo->hWindow, &clientRec);
        
        //create the buffer image
        _buffer = new Gdiplus::Bitmap(clientRec.right - clientRec.left, clientRec.bottom - clientRec.top, _currentGraphics);
        
        //create the graphics object to draw on the buffer
        Gdiplus::Graphics *bufferGraphics = Gdiplus::Graphics::FromImage(_buffer);
        
        /*Draw a bunch of stuff*/
        _currentGraphics->DrawImage(_buffer, 0, 0);
        Obviously, this isn't complete code, but the basic idea is still there. I create a new image to act as the buffer (line 6). Using that particular constructor creates a bitmap that is compatible with the "real" graphics object and is the size of the entire client area of the window. In order to draw on a bitmap with GDI+ you need a Graphics object for that particular bitmap (line 9). Then draw as usual with the buffer Graphics object. The final step is to draw the buffer image with the real graphics object.

        Well, I suppose the final step would be to clean up my _buffer and bufferGraphics objects.

        There may be other, better, ways to do this, but this was all that I could find when I was searching. Hope it helps.

        Comment

        Working...