Skip to main content
GameDev.net gamedev.net
🔒 Locked

Loading Bitmap to Surface

Started by silverwolf0 May 13, 2003 at 5:03 PM 1 replies 350+ views
Original Post
silverwolf0
silverwolf0
I am having trouble with getting a bitmap to display correctly in directdraw. I’m currently using this excerpt of code I copied from Tricks of Gaming Guru and for some reason my bitmap comes out distorted when blittered. Check out the difference: http://pages.sbcglobal.net/kenjisamurai/happy.gif (the gray is where the transparency is and yes the original pictures are 24bit bitmaps) Could this code be the culprit or something else? somesurface->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL); DWORD * tsome_buffer = (DWORD *)ddsd.lpSurface; // process each line and copy it into the primary buffer for (int index_y = 0; index_y < PICTOHEIGHT; index_y++) { for (int index_x = 0; index_x < PICTOWIDTH; index_x++) { // get BGR values UCHAR blue = (bitmap.buffer[index_y*PICTOWIDTH*3 + index_x*3 + 0]), green = (bitmap.buffer[index_y*PICTOWIDTH*3 + index_x*3 + 1]), red = (bitmap.buffer[index_y*PICTOWIDTH*3 + index_x*3 + 2]); // this builds a 32 bit color value in A.8.8.8 format (8-bit alpha mode) DWORD pixel = _RGB32BIT(0,red,green,blue); // write the pixel SOME_buffer[index_x + (index_y*ddsd.lPitch >> 2)] = pixel; } // end for index_x } // end for index_y // now unlock the primary surfac if (FAILED(somesurface->Unlock(NULL))) return(0);
Don''t email me. My mailbox is 100% full.
quasar3d
quasar3d
I think this code was made in the time textures had to be powers of two.

If a bitmap has a width that isn't a multiple of 4, there will be some padding bytes at the end of each scanline. A number that's a power is also a multiply of 4 (except 1 & 2).

your code should be:

    
int picpitch = (PICWIDTH * 3 + 3) & ~3;
UCHAR blue = (bitmap.buffer[index_y*picpitch + index_x*3 + 0]),
green = (bitmap.buffer[index_y*picpitch + index_x*3 + 1]),
red = (bitmap.buffer[index_y*picpitch + index_x*3 + 2]);


My Site

[edited by - Quasar3D on May 14, 2003 1:34:08 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.