Re: double buffering
- Posted by euman at bellsouth.net Aug 16, 2001
- 489 views
Here is an example from a current project I am working on.... Hope it explains things some -- Double buffer -- first create the initial DC and fill it with a compatible bitmap (magic bitmap) -- The CreateCompatibleDC function creates a memory device context (DC) compatible with the specified device. memdc = c_func(xCreateCompatibleDC, {hdc}) -- make sure we destroy this when we exit the prog hbit = c_func(xCreateCompatibleBitmap, {hdc, 640, 480}) -- select the brush for the background into the memdc along with the "magic bitmap" ;) -- The SelectObject function selects an object into the specified device context (DC). -- The new object replaces the previous object of the same type. -- in this case the objects are not the same (one is a brush and the other is a bitmap) junk = c_func(xSelectObject,{memdc, hbrush}) junk = c_func(xSelectObject,{memdc, hbit}) -- The PatBlt function paints the specified rectangle using the brush that is currently selected -- into the specified device context. The brush color and the surface color or colors are combined -- by using the specified raster operation. junk = c_func(xPatBlt, {memdc, 0, 0, 640, 480, PATCOPY}) bitdc = c_func(xCreateCompatibleDC, {hdc}) -- make sure we destroy this when we exit the prog -- run our function (defined above) to return an address to our Device Independant Bitmaps hDib = createDIB(butbar2[1], butbar2[2], hdc ) junk = c_func(xSelectObject,{bitdc, hDib}) junk = c_func(xBitBlt,{memdc, 517, 0, 114, 480,bitdc,0,0,SRCCOPY}) Count the DC's and note that BitBlt is used to fill the memdc with an image which in this case happens to be an image in bitdc. If I use bitdc as a temporary holder for a DIB I can place multiple images in memdc. The reason for this is when you need a Paint refresh, copying memdc to your hdc in one swoop is very-very fast. elsif iMsg = WM_PAINT then hdc = c_func(BeginPaint, {hwnd,ps}) junk = c_func(xBitBlt,{hdc, 0, 0,640,480,memdc,0,0,SRCCOPY}) c_proc(EndPaint, {hwnd, ps}) In my program I am copying 10 bitmap images to the screen all at once (code for all of this not in this message but this is a general overview) and there is no flicker or stacking look when the images are painted... Euman euman at bellsouth.net ----- Original Message ----- From: <dstanger at belco.bc.ca> To: "EUforum" <EUforum at topica.com> Sent: Tuesday, August 14, 2001 17:31 Subject: double buffering > > Hi all, > > When Derek was talking about graphic animation he mentioned the term "double > buffering". What is that? > > Thanks, > David S. > > > > >