🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Problem loading/displaying bitmaps.

Started by
3 comments, last by VisualLR 24 years, 7 months ago
Here see if this works for you.

yourbuffer[x + y*(lpitch >> 1)] = pixel or whatever.

Let me know if that worked. Good luck, friz

------------------
Still Learning...

[This message has been edited by frizb (edited November 19, 1999).]

Still Learning...
Advertisement
*sigh* seems like I keep interfering with bitmap problems *LOL*. I don't mind. I love it.

Okay, here is what I think you are doing, or at least a small part of it.

1) You have got a directdraw surface with the height and width of the image you are want to load.

2) You open the image.

3) Lock the surface, read in the BGR format pixels into unsigned char. Convert it to a 16 bit (either 1555 or 565....the one showed is for 1555)

unsigned short color = (unsigned short)( ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3) );

And then you put this value onto the directrawsurface.

Shouldn't be too difficult.

------------------
Dance with me......

Oh and I forgot to say that you have to add what is left to the directdrawsurface pointer

so....add the lPitch - DDSURFWidth to the surfacepointer.....

And keep in mind that a 24 bits bitmap is saved in reverse order (bottom to top) so you need to subtract 2 times the width each time.

------------------
Dance with me......

Hey, I wrote a bitmap loader today, but I had a small problem... see, I loaded a 24bit bmp and converted it to a 16bit one, the loading and conversion work fine, and to test it I wrote the converted bitmap to a file, when I open it with PSP or whatever it looks fine. BUT, when I draw it on a surface I have problems, cause I loaded the converted 16bit bitmap into a buffer that's 2*Width*Height in size, so, if I try to draw the bitmap onto a surface I get on one side the actual bitmap looking good, but right next to it I got another copy of the bitmap that's distorted.. so what I need to know is if I have to reduce the size of the converted buffer to Width*Height for it to actually work, or if it's just my blitter that's wrong... let me know if you need more details, cause I feel like I didnt make much sense if at all...

------------------
VisualLR
visuallr@netscape.net
http://www.geocities.com/SiliconValley/6276

Actually, that's not exactly what Im doing, this is what I do... (I made my class Bitmap that handles BMPs)

Bitmap image;
image.LoadBitmap("24BitGraphic.bmp");

so now the BMP is loaded and converted to a 16bit BMP stored in image.buffer

so now I lock the back surface (Im not using offsurfaces now, cause Im only interested in displaying the bitmap correctly at the time, I'll make it work better once it's actually working), after I lock the back surface I do something like this:

for (int i=0; i < (2*image.Height)-1; i++)
{
memcpy(SurfacePtr, image.buffer, image.Width);
SurfacePtr += 640;
image.buffer += image.Width;
}

and what that does is display HALF of the bitmap where it's supposed to be, then a gap between that and the other half...

However, if I do this:

for (int i=0; i < (2*image.Height)-1; i++)
{
memcpy(SurfacePtr, image.buffer, image.Width*2);
SurfacePtr += 640;
image.buffer += image.Width*2;
}

it displays the bitmap correctly on the top left corner, BUT, it displays a second copy of the bitmap after the gap, only the second copy of the bitmap is distorted (second half is drawn first, first half last)..

I know the bitmap loading/conversion part is working, cause if I write the converted bitmap to a file, it'll work fine when I open it with PSP. So Im thinking my problem is in the actual blitting of the image (the colors work fine, btw).

Thanks!

------------------
VisualLR
visuallr@netscape.net
http://www.geocities.com/SiliconValley/6276

This topic is closed to new replies.

Advertisement