Archived

This topic is now archived and is closed to further replies.

BigSassy

Odd problem loading bitmaps

Recommended Posts

Hey everybody. My bitmap loading routine skews/messes up certain images. My 800x600 background is totally messed up when I load it in. I'm sure you've heard this problem before. When I searched the forums some people said that the file needs to be multiples of 4. Since the bitmaps are loaded with DWORD's you have to account for the padding at the end of each line if you don't make them divisible by 4. The thing is mine worked fine on a computer with a TNT2 card, but doesn't work on a Voodoo Banshee. And it seems that they need to be divisible by 8. So I don't think my problem is the padding from DWORD's. You may be thinking "800 is divisible by 8? Shouldn't it be working?" That's really perplexing me as well. It seems to work with all numbers divisible by 8 except for 800. My display mode is 800x600x16. I have a clipper on the backsurface (where I'm blitting the bitmap to) that's 800x600 (the screen boundries). Anybody have any ideas on what could be going wrong? EDIT: If I load the sprite into a surface into system memory, it works with multiples of 4. Any ideas on why it wouldn't work in video memory? Edited by - BigSassy on June 28, 2001 12:55:18 PM

Share this post


Link to post
Share on other sites
Are you locking the surface and copying the memory directly? Check the lPitch member of the DDSURFACEDESC2, and try to avoid copying the memory directly.

If you want to make your life easier, you can just load the bitmap into a memory DC, then use the surface''s GetDC function, then BitBlt it across.

Share this post


Link to post
Share on other sites
The pitch is ok. I know that my life would be easier if I used windows or DDLoadBitmap but what kind of programmer could I call myself if I can''t even load in a simple bitmap? I do appreciate the help though

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
''the file needs to be multiples of 4''

Not sure if this helps, but I''ve found that it''s each horizontal row in the bitmap that must be evenly divisable by 4. So in the case of a 2x2 24-bit bitmap, each row would contain 6 bytes of pixel data, and 2 bytes of padding, from left to right like this:

GBRGBRPP
GBRGBRPP

G = Green
B = Blue
R = Red
P = Padding byte

I use this little formula to tell me how many bytes to read in per row:

int iBmpBytesPerRow = (m_biWidth * 3) + (m_biWidth % 4);

where m_biWidth is the width of the image, e.g 800.

Maybe I misunderstood when you said that the file needs to be a multiple of 4, cuz I''ve always thought of it being the rows. Anyway, using this formula and compensating for the pitch of the surface has always worked for me, so I thought I share it.

Share this post


Link to post
Share on other sites
Oops, that Anonymous poster meant to say:

BGRBGRPP
BGRBGRPP

B = Blue
G = Green
R = Red
P = Padding byte


Blue before green...

Edited by - PigVomit on June 30, 2001 3:07:32 PM

Share this post


Link to post
Share on other sites
I got it working. It was actually a couple problems. The pitch was the video mode problem (I was doing something dumb when testing it the first time). And once I took care of the pitch, the code I wrote to take of the padding worked, so life is peachy. Thanks for the help guys

And yeah, I meant the rows needed to be divisible by 4, not the total file size.

Share this post


Link to post
Share on other sites