Texture on a D3D Sprite being automatically resampled?

Babutian

Newcomer
Joined
Oct 15, 2005
Messages
1
Hi there,

im using D3D sprites in my 2D game. Im storing textures in jpg and tga files, every time im creating a sprite with, say 150x150 tga texture file all seems to wrok fine, but my sprite's texture is being automatically resampled to fit 256x256. i have absolutely no idea why. any help would be greatly appreciated. ah yes, here is the code:


....
....
....
texture = TextureLoader.FromFile(device, @filename);
SurfaceDescription description = texture.GetLevelDescription(0);
textureSize = new Rectangle(0, 0, description.Width, description.Height);
....
....

Width and Height Fields semm to always be 256... :o
 
The Direct3D sprite class also has some wierd behavior, seen here http://www.gamedev.net/reference/articles/article1608.asp. It may or may not relate to your issue; however, I don't know alot about the sprite class in Direct3D. I know that ThePentiumGuy did a tutorial on Texturing a Quad, ie. making your own sprite class. I have had great success building of that base. I know it is not fun to rewrite working code, but I think you would find better luck with texturing your own quads, you have more control.
 
I do believe that a texture must have dimensions that are powers of two, for example, 64,64, or 128,128, or 256,256. If you provide an image that is 150,150 it must be resampled in order to be compatible with graphics hardware.

I'm not positive that this can be done with a sprite, but it should be doable with a quad: Use a 256x256 texture on a 256x256 sprite/quad with a mask so that the area beyond 150,150 simply won't be visible. Of course, masks don't work so well with lossy image formats, so you would have to ditch the jpgs.
 
Marble's right, only high-end video cards support non power of 2 sized textures. However, you can just pad your jpg's to 256x256 and pass a 150x150 rectangle to the sprite's Draw function.
 
you must use
texture = TextureLoader.FromFile(device, @filename, 0, 0, 1, Usage.None, Format.Unknown, Pool.Managed, Filter.None, Filter.None, 0);

in place of
texture = TextureLoader.FromFile(device, @filename);

;)
 
Back
Top