Bitmaps using DirectX

Started by
21 comments, last by giant 22 years, 4 months ago
As newer versions of DirectX came out, new interfaces were developed. The old ones are still accessable, but it is always recommended to use the new ones. So in the case of LaMothe''s book, he wrote it using DirectX v6. So to get the most up to date interface, he creates a LPDIRECTDRAW interface and then queries for an LPDREICTDRAW4 interface. This is the part of the code that you used:

LPDIRECTDRAW4 lpdd = NULL; // dd4 object

...
...
...

LPDIRECTDRAW lpdd_temp;

// first create base IDirectDraw interface
if (FAILED(DirectDrawCreate(NULL, &lpdd_temp, NULL)))
return(0);

// now query for IDirectDraw4
if (FAILED(lpdd_temp->QueryInterface(IID_IDirectDraw4,(LPVOID *)&lpdd)))
return(0);

Now when you use the LPDIRECTDRAW4 interface, you have to use the LPDIRECTDRAWSURFACE4 for surfaces. If you downloaded the DirectX 7 or 8 SDK from microsoft, the DDUtil function LoadBitmap returns a surface that is an LPDIRECTDRAWSURFACE7, which is not the same, so it just doesn''t work.

---
Make it work.
Make it right.
Make it fast.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
Advertisement
When you say they look strange when you display they, I *might* be able to help. I had a heck of a time coding a bitmap loader myself earlier this year (I also used LaMothe's book for reference) and got help from these boards. The problem, it turned out, is that the .bmp format for some reason requires images to have a width that is a multiple of 4. If it is not, it adds enough 0's to the end of each row of the image to make it that wide.

So, if you had a picture that was 50 pixels wide, for example, there would be two additional bytes of 0 at the end of each line, to bump it up to 52 pixels wide (52 = 13 * 4 so it's a multiple of 4). If you ignore this fact, sometimes you will end up reading in these 0's instead of the real image data, which causes your image to look really weird .

To get around it, do something like this:

    char junk[3]; // Temporary variable to hold the 0'sif(imageWidth%4!=0){  read(junk,imageWidth%4);}  


I don't know how much C++ you know, so I'm sorry if this seems basic. In the above, basically it checks if the image is a multiple of 4 pixels wide (you can get the width from the image header), and if it is, does nothing. If it is not, however, it reads in all the extra 0's. That is what the width%4 does, calculate how many 0's the width needs to be a multiple of 4.

Add this feature to your code, and it might not look messed up anymore! Hope that helps,

Anthracks

EDIT: Fixed a stupid typo.

Edited by - Anthracks on December 13, 2001 9:14:11 PM
Hi CaptainJester!

What types will I use to make it work?
I do not fully understand this crap.

Do you have a code example or anything that might explain it to me.

Giant

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." --Albert Einstein

Edited by - giant on December 14, 2001 6:18:33 AM

This topic is closed to new replies.

Advertisement