Jump to content
  • Advertisement
Sign in to follow this  
coolblue

Textures

This topic is 4809 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

I am attempting to create a texture object with the following code texture = Direct3D.TextureLoader.FromFile( graphics, "greenbg.bmp", 0, 0, 0, 0, Direct3D.Format.Unknown, Direct3D.Pool.Managed, Direct3D.Filter.Linear, Direct3D.Filter.Linear, Color.FromArgb( 0, 0, 255 ).ToArgb() ); greenbg.bmp is a 640*480 bitmap but this code creates a 1024*512 texture!! If I change greenbg.bmp for a 32*32 bitmap it creates a 32*32 texture when I change this for a 512*512 bitmap it correctly creates a 512*512 texture!, can anyone tell me why it does not work with a 640*480 bitmap? (this is driving me mad!!)

Share this post


Link to post
Share on other sites
Advertisement
DirectX is forcing the dimensions of the texture to be a power of 2. 640 and 480 aren't powers of 2, so they are resized to the next power of 2 (1024 and 512). This is very common issue with both OpenGL and DirectX. The best thing to do is make sure your textures are already powers of 2 in size.

If you want a 640x480 image, create it in a 1024x512 bmp and only display the 640x480 portion of that.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dave Hunt
If you want a 640x480 image, create it in a 1024x512 bmp and only display the 640x480 portion of that.


Or better yet, load a TGA or PNG to save on space. :)

(Unless DX converts all textures to BMP format at the end -- can anyone confirm this?)

Share this post


Link to post
Share on other sites
Thank you for the replies, I will give you suggestions a try.

One more question though. Is the best way of displaying a background image to create a large sprite and draw it first or is there a specific way to create backgrounds?

Share this post


Link to post
Share on other sites
Quote:
Original post by HopeDagger
Quote:
Original post by Dave Hunt
If you want a 640x480 image, create it in a 1024x512 bmp and only display the 640x480 portion of that.


Or better yet, load a TGA or PNG to save on space. :)

(Unless DX converts all textures to BMP format at the end -- can anyone confirm this?)


Any image format you load doesn't exist in the hardware. Only compressed textures (DXT1 to 5) are staying compressed in the hardware (if it's supported). Every other texture will be fully expanded to its image size.

So it doesn't matter if he's using BMP, TGA or PNG. Just stay away from lossy image formats like jpg if you want to recognize your textures.

Share this post


Link to post
Share on other sites
My problem is that I am designing a game that runs in a 640*480 window. I want to display a 640*480 texture as a background without it being stretched and distorted. It appears that the only way to do this is to put my 640*80 texture onto a 1024*512 bitmap and just display the 640*480 part. How is this done and surely this is a waste of memory space? I would have thought many people have come across this problem due to screen resolutions not being in powers of 2. All of the tutorials I have seen either don't use backgrounds or use tiled backgrounds or square windows (ie they all seem to divert around the problem).

Share this post


Link to post
Share on other sites
You can split the background in one 512x512 and another 128x512 or in 256x256 squares (to be on the complete safe side) or use the wasted space for other content.

Up till now i'm still using 256x256 textures max and split the bigger ones up as i'm trying to target even oldest hardware.

Share this post


Link to post
Share on other sites
Thanks for all your help. I have now got my background to look correct (although the tutorial I was playing with sets the anchor point for the camera at its center so I have had to play around with the x,y co-ordinates to get it to line up properly!) I took your advice and displayed the 640*480 portion of a 1024*512 bitmap.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!