Jump to content
  • Advertisement

Archived

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

giant

Bitmaps using DirectX

This topic is 6062 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It doesn''t have anything to do with 4.
You must use powers of 2 .

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!