[.net] Stretched D3DX Sprite

Started by
17 comments, last by Uphoreum 17 years, 6 months ago
I'm using the D3DX Sprite object to draw 2D textures to the screen. For some reason, the texture is stretched. The textures is 640*480, the size of the window. Here's the "Draw2D" code:

this.Sprite.Draw2D(this.MenuBackground, new Point(0, 0), 0.0f, new Point(0, 0), Color.White);
[/SOURCE]
The first parameter is the texture, the second is the "rotational center", next is the rotational degree, then the coordinate for drawing, and the overlay color. Any idea why this might cause the image to be stretched? Need more information?
Advertisement
What kind of texture filtering do you have enabled and are you sure your card supports non-power of 2 textures? Try turning filtering off and see if that corrects it.
Right now, only AlphaBlending is on, not that I'm using it.
As for powers of 2, I'll have to check. I'm so used to pure 2D pixel drawing that I forget about this sort of 3D related thing.
Yep, power of 2 is the problem.

I didn't know about this restriction. What if I want an image to be of a size not ^2? Do I have to "build" it out of power of 2 sized images?
Quote:Original post by Uphoreum
I didn't know about this restriction. What if I want an image to be of a size not ^2? Do I have to "build" it out of power of 2 sized images?


I have a hard time believing your card doesn't support non-^2 textures unless it's really, really old. Anyway if you're sure, then what you can do is either build it out of smaller textures or just compensate for your cards strecting.

See right now it's being strected to 1024x512, if you turn filtering off it should just pad the extra space. Then use the draw overload that takes a rectangle and set it to (0,0,640,480). Depends on your card though, it might be best to just make a 1024x512 texture and add the 640x480 one to it.

Well, the card is a GeForce 6600GT. It's still made, it's not really old. Could their be some sort of setting for the D3D Device that controls this?
Can you post your code for setting up the device and the code for loading the texture?
Yep,
Device:

//Setup Presentation PerametersPresentParameters Parameters = new PresentParameters();//One Back BufferParameters.BackBufferCount = 1;//Set Our Window As Device's WindowParameters.DeviceWindow = Window;//No V-SyncParameters.PresentationInterval = PresentInterval.Immediate;//Discard Old framesParameters.SwapEffect = SwapEffect.Discard;//Set As WindowedParameters.Windowed = true;//Create The DeviceDevice Device = new Device(0, DeviceType.Hardware, Window, CreateFlags.SoftwareVertexProcessing, Parameters);


Texture:
this.MenuBackground = TextureLoader.FromFile(this.Device, "data/menu/menuBackground.bmp");

Try this:

this.MenuBackground = TextureLoader.FromFile( this.Device, "data/menu/menuBackground.bmp", 0, 0, 1, Usage.SoftwareProcessing, Format.A8R8G8B8, Pool.Managed, Filter.None, Filter.None, 0 );

Wow, it worked. What happened?

This topic is closed to new replies.

Advertisement