The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: cman on November 11, 2010, 08:43:41 PM

Title: Double Buffering
Post by: cman on November 11, 2010, 08:43:41 PM
Does anyone have example code using double buffering for an animation? From what I've read one simply sets up an offscreen bitmap and device context for an animation's background , uses "BitBlit" to add any animated elements on top of the offscreen bitmap and then bitblits the offscreen bitmap to the desired Windows control surface. Am I correct here? Thanks for any input....
Title: Re: Double Buffering
Post by: jj2007 on November 11, 2010, 08:48:24 PM
Search the forum for CreateCompatibleDC - there are many good examples.
If that is not enough, search \masm32\examples for the 33 assembler files containing the string CreateCompatibleDC.
Title: Re: Double Buffering
Post by: Coma on November 12, 2010, 01:16:11 PM
If you like to display an animation there is a simple way without CreateCompatibleDC, BitBlt Bitmap action.
Use CreateWindowEx with the animation control class.
The avi must be silent and you can load it from HDD or include it in resource.

szSysAnimate32     db "SysAnimate32",0

Only an idea.
Title: Re: Double Buffering
Post by: Farabi on November 13, 2010, 09:31:26 AM
You can use this, you will only need donkey graph lib


fLayer struct
DC dword 0
bmp dword 0
fLayer ends

fNewLayer proc uses esi lpLayerStruct:dword,_width:dword,height:dword

mov esi,lpLayerStruct
invoke CreateCompatibleDC,0
.if eax==0
invoke MessageBox,0,0,0,0
.endif
mov [esi].fLayer.DC,eax
invoke CreateIndependantBitmap,eax,_width,height
mov [esi].fLayer.bmp,eax
invoke SelectObject,[esi].fLayer.DC,[esi].fLayer.bmp
invoke DeleteObject,eax


ret
fNewLayer endp

fDeleteLayer proc uses esi lpLayerStruct:dword

mov esi,lpLayerStruct
invoke DeleteObject,[esi].fLayer.bmp
invoke DeleteDC,[esi].fLayer.DC

ret
fDeleteLayer endp


How to use it:

.data
gbuff fLayer <?>
.code
.elseif WM_CREATE
invoke fNewLayer,addr gbuff,1024,768
; Draw everything to gbuff.DC
.endif

;On your draw procedure
invoke BitBlt,hDC,0,0,1024,768,gbuff.DC,0,0,SRCCOPY


Easy is not it?