Bitmaps using DirectX

Started by
21 comments, last by giant 22 years, 4 months ago
Hi. I am trying to load and display bitmaps using DirectX. I am loading the bitmap ok, and creating the surface, but when I try and display it, if is all messed up. The resolution I am using is 640 x 480, and if I load a bitmap of this size and create a surface the smae size, that bitmap is displayed correctly, however if I try and display a bitmap of a smaller size, (the one I am trying to use is 81x122) it loads and creates the surface fine, but it is displayed to the screen as a pile of garbage. Any ideas? Giant "Only two things are infinite, the universe and human stupidity, and I''m not sure about the former." --Albert Einstein
Advertisement
hrmm.. How are you loading your bitmaps? Are you taking pitch into account? Does your device support non-power-of-two textures?

If you are using DX8, you might want to consider using D3DXCreateTextureFromFileEx.

xyzzy
Hi
I am using Code taken from "The Tricks of the Windows Programming Guru''s". The bitmap has 256 colours.

I am using DirectX 7, so I dount know if that will be available to use.

I just dont understand why, it works for full screen bitmaps but not for smaller ones.

"Only two things are infinite, the universe and human stupidity, and I''m not sure about the former." --Albert Einstein
The problem is that the file your using does not have a width which is a power of four. What happens is that when a program saves a bitmap it saves each line and wants it to be a power of four. Since yours is just 81 in width it pads it to 84 with 0s. Your best bet is to load the bitmap normally, find out the next multiple of 4 (in this case 84), and create two surfaces. The first surface will have the new width of 84, the second will have the old width of 81. First copy the bitmap to the first surface using the width of 84. Second blit the first surface to the second (make sure you bound the first surface to the correct width of 81). Then your done.
Hi.
Thanks for the info. Do you mean a multiple of 4 or a power of 4? There is a huge difference. I cannot imagine it being a power of 4, cause then there would only be a few size bitmaps that you would be able to load.

Again, thanks for the info.

Giant

"Only two things are infinite, the universe and human stupidity, and I''m not sure about the former." --Albert Einstein
Your bitmap does not have to be a multiple of 4. I have loaded a bitmap that was 310 x 50 and neither dimension is a multtiple of 4 and I have no problems. If you are using LaMothes code to load the bitmaps, I find that his stuff is more complpex than it needs to be. Try using the DDUtil.cpp that comes with DirectX. It is much easier to use. You just give it the file name and it loads the bitmap and returns an OFFSCREEN_PLAIN surface containing your bitmap that you can easily blit to the back buffer.

PS. I thought that that book was great, except I never use his libs, I find they are more cryptic and complex than needed.


---
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]
It doesn''t have anything to do with 4.
You must use powers of 2 .
Direct3D likes powers of 2, but DirectDraw (which i think giant is using) doesn''t mind.
However, .BMP format images are stored with lines padded to multiples of 4 bytes. LaMothe doesnt seem to take any note of this in his book (not that i could see). Think about these bytes when maniuplating the buffer containing the image, and strip them out when copying to the surface.
Let me try to simplify what they are saying:

LaMothe''s code works, but this bitmap loading function only works on bitmaps that have dimenions that are a power of(2 or 4).

I suppose you could stick with those kinds of bitmaps or fix his function.

Another option is to use a better function like those listed above.

^^^^^^^^^^^^^^^^^^^^^^^^^
Wait, wait, wait....who''s Nambla Fett?
-- What would Sweetness do?
Thanks Everyone for you help.

I have never heard of DDUtil.cpp but will try and use it. What function calls do I use to achive what you were saying about off screen plains.

Thanks
Giant

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

This topic is closed to new replies.

Advertisement