My texture displays stretched vertically and I have no idea why. I loaded it using TextureLoader and used Sprite.Draw2D(texure, rectange, size, position, Color.White). I always set the rectangle and the size to the same. Can anyone help I'm new at this stuff. Thanks!

Stretched Texture
jstar
rhyd
Dazza1412
Shanta Appukuttan
No but you can't use the easy API overloads since they assume square
use
myTexture = new Texture(e.Device, Utility.FindMediaFile("texture.dds"), XSIZE, YSIZE, 1, Usage.None, Format.A8B8G8R8, Pool.Managed, Filter.Point, Filter.None, 0, false, null);
And all should be well.
If your textures are square and a power of 2 you can use the simpler
myTexture
= new Texture(e.Device, Utility.FindMediaFile("texture.dds"));Remember that though Sprite will work with x,y coordinates under the covers textures u,v coordinates are always 0.0-1.0. Sprite is just doing the math for you.
JimSeidel
You could also see if your hardware supports non-power of 2 texture by checking the device caps.
I hope this helps.
Take care.
bY73-_-j0b
I don't get it... does this mean that any graphic files I import in my program have to be changed so that they're square shape What if my background's 800x600 What if my character is taller than he is wide
And if I do have to make all of my external bitmaps squares, then how am I supposed to know where to crop them Some might have a whole whack of blank space to make them a square, and others might have very little...
John rambo
misbrisco
Here's a method I developed that is quite effective at turning a Bitmap into a texture (and gets around the square problem):
protected D3D.Texture BitmapToTexture( D3D.Device graphics, ref Bitmap bmp )
{
MemoryStream loMS = new MemoryStream();
// Create a square offscreen bitmap, the dimensions of which are
// the size of the greatest dimension of the original bitmap
Bitmap osBmp = new Bitmap( (int)Math.Max( bmp.Width, bmp.Height ), (int)Math.Max( bmp.Width, bmp.Height ) );
// Draw the original bitmap into the top-left corner of the new bitmap
Graphics osg = Graphics.FromImage( osBmp );
osg.DrawImage( bmp, 0, 0, bmp.Width, bmp.Height );
// Use the new square bitmap as the texture
osBmp.Save( loMS, System.Drawing.Imaging.ImageFormat.Bmp );
loMS.Seek( 0, 0 );
return D3D.TextureLoader.FromStream( graphics, loMS );
}
You'll end up with a texture that has whitespace at the edges, so that it still forms a square, but your original bitmap will keep it's proportions. When drawing your sprite, just leave the whitespace out.