Archived

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

Diego

Loading a Bitmap from a file onto a DDSurface

Recommended Posts

New Question (4/1/00): The previous answers were very helpful, thank you all. I've played around with the different methods, there's just one thing I don't understand. What GDI functions can I use to load a bitmap in such a way that I can then Blit it to the DDSurface? I've been looking over Win32 SDK help files, but there's a lot of confusing stuff about HANDLE, HGDIOBJ, HBITMAP and so on. Are these all the same thing? If so, what are the best functions to load a bitmap, get it's hdc, and blit it to a DDSurface? Thanks again. Original Message: What is the simplest way to get a bitmap from a file onto a Direct Draw Surface? I've been working with LaMothe's famous "Windows Game Programming for Dummies" but there is one thing in the DirectDraw chapters that doesn't sit well with me. LaMothe uses his own custom (and quite complex) function to load a bitmap onto a surface. To make matters worse this function just doesn't work with 16 or 24-bit images on my video card (I assume it is a problem with the bit macros because the colors come out wrong). What I need to know is, what is the simplest way to get a bitmap from a file onto a Direct Draw Surface? I have a feeling there is some way to load the bitmap into the app using GDI functions and then just bitblt it over to the surface. Or maybe there is even some load function within the DDSurfaceDesc class that I just don't know about. Oh yeah, and I'm not concerned with speed as this function will be more of an initialization function. It's cold and there's wolves... Help me! -Diego Check out my cool games at: http://staticlounge.tripod.com/ Edited by - Diego on 4/1/00 2:34:26 PM

Share this post


Link to post
Share on other sites
Actually, Lamothes function is not that hard Plus he has a new book out called Tips and Tricks of the windows game programming gurus it is an ypdate and he tell you about 24 and 32 bit.

Share this post


Link to post
Share on other sites
The simplest way I can think of is by using the ddutil functions: DDLoadBitmap() and DDReLoadBitmap(). The ddutil files can be found in one of the DX folders. DDLoadBitmap() creates a surface and loads a bitmap onto it, where as the DDReLoadBitmap() function loads a bitmap into an already created surface.
To still use LaMothe''s functions you need to determine what pixel format using the function GetPixelFormat() look it up in the DX help files.

Share this post


Link to post
Share on other sites
Diego,

As far as LaMothe''s loading function, do you mean it loads it, but the colors come out funny?

If so, this is probably why:

The macro he provides to fill in the USHORT goes something like this:

RGB16BIT(r,g,b)((b%32)+((g%32)<<5)+((r%32)<<10))
(I think that''s how it goes, I loaned the book out :-))

That makes a 5.5.5 RGB format with the most significant bit being the alpha. Some video cards don''t like that.

They want to see:

RGB16BIT(r,g,b)(((b%32)<<1)+((g%32)<<6)+((r%32)<<11))

Which is 5.5.5 with the least significant bit being alpha.

or:

RGB16BIT(r,g,b)((b%32)+((g%64)<<5)+((r%32) << 11))

Which is 5.6.5 with no alpha.

Please let me know if that made the function work right.

Kaellaar

Share this post


Link to post
Share on other sites
Hi

Another Method is to compile the Bitmaps as resources. You can than Load them in your App, and Blit them to a DirectDraw Surface.
Usefull when you wan''t everything in one File (when creating screensavers) !

Lars

Share this post


Link to post
Share on other sites