views:

42

answers:

1

I was coding a snake game, and i got an apple image to use in the game, so i created a DC and then loaded the apple to this DC, when the game is running, it should copy the apple to the buffer and then the buffer to the screen, but the apple ends black and white in the screen, any1 has idea why? here is some of my code, might help...

"apple-loading procedure"

invoke GetModuleHandle,0
invoke LoadBitmap,eax,10
push eax
invoke CreateCompatibleDC,0
pop ecx
mov [mapple],eax
invoke SelectObject,[mapple],ecx 

"buffer-creation procedure"

invoke CreateCompatibleDC,0
mov [mdc],eax
invoke CreateCompatibleBitmap,[mdc],800,600
mov [mbmp],eax
invoke SelectObject,[mdc],[mbmp]
invoke SetBkMode,[mdc],TRANSPARENT
invoke SetTextColor,[mdc],0FFFFFFh 

Calls to BitBlt function

invoke BitBlt,[mdc],[applex],[appley],20,20,[mapple],0,0,SRCCOPY 


invoke GetDC,0
invoke BitBlt,eax,0,0,800,600,[mdc],0,0,SRCCOPY
+2  A: 

From elsewhere the idea that you need to pass CreateCompatibleBitmap the actual DC you're targetting (e.g. GetDC(NULL)) rather than the just created mdc. Because after CreateCompatibleDC, the current (=initial, default) bitmap is a monochrome pixel 1x1x1b that CreateCompatibleBitmap(mdc...) will match.

pascal
+1 I've made this mistake more times than I like to admit.
Adrian McCarthy