Textures

Started by
6 comments, last by coolblue 18 years, 7 months ago
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!!)
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.
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?)
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?
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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

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).
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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

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.

This topic is closed to new replies.

Advertisement