DDraw: reading in 16-bit bitmaps
Hi
i got the book ''Windows Game Programming for Dummies'' a while ago, and am doing stuff with bitmaps.. loading them in etc
well the author of WGPFD mainly uses 8bit colour in the book, and he gives some code to load in a 16bit bitmap, but it screws up all the colours, and he doesn''t explain how to use the blitter propley with them
so could someone please explain and post an example of loading in a 16bit .bmp, and displaying it using the blitter?
thx a heap
Yep, I had that same problem years ago.
There''s a problem with his Load_Bitmap_File function (or whatever it''s called) in one of the library source files.
The problem is that there''s no such thing as a 16-bit BMP file, he just loads a 24-bit true colour one, and converts it. The problem is his macro to convert true colour to 16-bit. I think it''s something to do with the scaling, and sometimes he uses ''&'' symbols in the macro when he means ''%'' or vice versa.
Compare all the code examples, and then mail him to complain that he should check his own code. In fact, the CD I got with Trick of the Win Game Proggging Gurus was semi-corrupted (that book''s basically the same as WGPD) and it took the publishers over 4 months to send me a replacement.
========
Smidge
www.smidge-tech.co.uk
========
There''s a problem with his Load_Bitmap_File function (or whatever it''s called) in one of the library source files.
The problem is that there''s no such thing as a 16-bit BMP file, he just loads a 24-bit true colour one, and converts it. The problem is his macro to convert true colour to 16-bit. I think it''s something to do with the scaling, and sometimes he uses ''&'' symbols in the macro when he means ''%'' or vice versa.
Compare all the code examples, and then mail him to complain that he should check his own code. In fact, the CD I got with Trick of the Win Game Proggging Gurus was semi-corrupted (that book''s basically the same as WGPD) and it took the publishers over 4 months to send me a replacement.
========
Smidge
www.smidge-tech.co.uk
========
oh... well at least it isn''t me
could anyone post some working code for this type of thing?
or are there some tutorials somewhere on this type of thing... ill go check on gd homepage now..
could anyone post some working code for this type of thing?
or are there some tutorials somewhere on this type of thing... ill go check on gd homepage now..
Hi Quantum!
I've also read WGPFD and i had the same problem with the bitmap loading code. So i made my own, but I used GDI to load it. If you got any questions or so, ask!
By the way, destx and desty is the destination coordinates on the destination surface.
Hope I helped
Edited by - eckax on August 8, 2000 8:11:27 AM
Edited by - eckax on August 8, 2000 8:14:37 AM
I've also read WGPFD and i had the same problem with the bitmap loading code. So i made my own, but I used GDI to load it. If you got any questions or so, ask!
void LoadBitmap(IDirectDrawSurface ** lpdds, LPCTSTR szbitmap, int width, int height, int destx, int desty) { HDC surfaceHDC = NULL; // Handle to the DC the surface uses HDC imageHDC = NULL; // Handle to the DC the image uses HBITMAP hbitmap; //Handle //Load in bitmap and get a handle to it hbitmap = (HBITMAP)LoadImage(NULL, szbitmap, IMAGE_BITMAP, width, height, LR_LOADFROMFILE | LR_CREATEDIBSECTION); //Create a DC that the image will use, GDI function imageHDC = CreateCompatibleDC(NULL); //This function puts the bitmap in the DC, its a GDI function SelectObject(imageHDC, hbitmap); //Lock the surface and get the DC (*lpdds)->GetDC(&surfaceHDC); if(ddtestval == DD_OK) { //StretchBlt is a GDI function that compresses or streches the bitmap if necessary StretchBlt(surfaceHDC, destx, desty, width, height, imageHDC, 0, 0, width, height, SRCCOPY); (*lpdds)->ReleaseDC(surfaceHDC); } } DeleteObject(hbitmap); DeleteDC(surfaceHDC); DeleteDC(imageHDC); }
By the way, destx and desty is the destination coordinates on the destination surface.
Hope I helped
Edited by - eckax on August 8, 2000 8:11:27 AM
Edited by - eckax on August 8, 2000 8:14:37 AM
Using LoadBitmap or LoadImage is lame. By writing it yourself you have a greater degree of flexibility and can use PAK files. At some point I''ll post a complete replacement for Andre''s Load_Bitmap_File().
You can just overwrite it and it''ll work!
========
Smidge
www.smidge-tech.co.uk
========
You can just overwrite it and it''ll work!
========
Smidge
www.smidge-tech.co.uk
========
thanks eckax, that gave me a better idea of what i should be doing, but i dont really wanna use GDI at all
smidge_tech: that would be great if you could do that
smidge_tech: that would be great if you could do that
It''s taking me a while to find the code.
Try shifting each component you pass to the _RGB565 macro right by 3.
i.e. Whenever you do this:
SixteenBitCol = _RGB565(red, green, blue);
do this:
SixteenBitCol = _RGB565(red >> 3, green >> 3, blue >> 3);
I can''t remember exactly how I fixed his code, but it was something along th lines of that. Try it, it might just work.
========
Smidge
www.smidge-tech.co.uk
========
Try shifting each component you pass to the _RGB565 macro right by 3.
i.e. Whenever you do this:
SixteenBitCol = _RGB565(red, green, blue);
do this:
SixteenBitCol = _RGB565(red >> 3, green >> 3, blue >> 3);
I can''t remember exactly how I fixed his code, but it was something along th lines of that. Try it, it might just work.
========
Smidge
www.smidge-tech.co.uk
========
smidge_tech, with your macro I got the Load_Bitmap_File to work but the colors are still a litle strange, but that shouldn't be any problem to solve, but I wont use the GDI function anymore
Edited by - eckax on August 9, 2000 7:34:34 AM
Edited by - eckax on August 9, 2000 7:34:34 AM
Nice to know!
Expect that reliable code replacement soon; if I''ve forgotten, email me.
========
Smidge
www.smidge-tech.co.uk
========
Expect that reliable code replacement soon; if I''ve forgotten, email me.
========
Smidge
www.smidge-tech.co.uk
========
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement