Display 24-bit bitmap has a problem
When I copy a bitmap from double_buffer to primary_buffer
has a problem like this:
http://202.206.208.253/bbs/UploadFile/2006-4/200642311123025501.bmp
one line display the bitmap but the next display black...
If you cann't see the bitmap please tell me. I will send a E-MAIL to you.
Please Help!
DisplayMode 640*480*32 and bitmap 24-bit
some code
DWORD *dest_ptr = primary_buffer;
DWORD *src_ptr = double_buffer;
// memory is non-linear, copy line by line
for (int y=0; y < SCREEN_HEIGHT; y++)
{
// copy line
memcpy((void *)dest_ptr, (void *)src_ptr, SCREEN_WIDTH*4);
// advance pointers to next line
dest_ptr+=ddsd.lPitch;
src_ptr +=SCREEN_WIDTH*4;
} // end for
The pitch is given in BYTES per line, but you add it onto a DWORD (32bit) pointer. If you increase a pointer it will be increased in the pointees size. In your code if you add the pitch you really add the pitch multiplied by 4 (4 bytes in a DWORD). You also multiply SCREEN_WIDTH by four which will have the same effect.
Changing the DWORD* of dest_ptr and src_ptr to BYTE* should do the trick. You may have to cast if your primary_buffer and double_buffer are DWORD (pointers or arrays):
BYTE* src_ptr = (BYTE*)double_buffer;
BYTE* dest_ptr = (BYTE*)primary_buffer;
Changing the DWORD* of dest_ptr and src_ptr to BYTE* should do the trick. You may have to cast if your primary_buffer and double_buffer are DWORD (pointers or arrays):
BYTE* src_ptr = (BYTE*)double_buffer;
BYTE* dest_ptr = (BYTE*)primary_buffer;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement