[.net] Stretched D3DX Sprite

Recommended Posts

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?

Share on other sites
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.

Share on other sites
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.

Share on other sites
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?

Share on other sites
Quote:
 Original post by UphoreumI 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.

Share on other sites
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?

Share on other sites
Can you post your code for setting up the device and the code for loading the texture?

Share on other sites
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");

Share on other sites
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 );

Share on other sites
Wow, it worked. What happened?

Share on other sites
Quote:
 Original post by UphoreumWow, it worked. What happened?

The function you where using has linear filtering on by default, which strected the texture to 1024x512 in memory since filtering requires a power of 2 texture. I used the full function and disabled the filter(see Filter.None), forcing it to use the 640x480 version.

Share on other sites
Wow, so much to think about!

Share on other sites
I've run into an issue involving the solution to this problem. I have some PNG graphics, that have an alpha channel so they can be semi-transparent. If I try to load these graphics with the full function overload, it messes up the semi-transparency, like so:

Direct3D.TextureLoader.FromFile(this.VideoDevice, "data/images/paddle.png", 0, 0, 1, Direct3D.Usage.SoftwareProcessing, this.VideoDevice.DisplayMode.Format, Direct3D.Pool.Managed, Direct3D.Filter.None, Direct3D.Filter.None, 0);

I'm sure one of these perameters can fix it. If I load it with the short overload like this:

Direct3D.TextureLoader.FromFile(this.VideoDevice, "data/images/paddle.png);

It works just fine, but it stretches the image like previously mentioned because of linear filtering or whatever you said ;-)

Anyone know what I should do?

Share on other sites
The last parameter(0) is the colorkey, which is probably messing things up. Also make sure VideoDevice.DisplayMode.Format contains an alpha channel.

Quote:
 TextureLoader.FromFileA value to replace with transparent black, or 0 to disable the color key. This is always a 32-bit ARGB color that is independent of the source image format. Alpha is significant, and usually should be set to FF for opaque color keys. For example, for opaque black, the value is equal to 0xFF000000.

Share on other sites
What should I set that parameter to?

How can I tell if my device format supports an alpha channel?

Share on other sites
Quote:
 Original post by UphoreumWhat should I set that parameter to?How can I tell if my device format supports an alpha channel?

I think disabling the color key should leave transparency working correctly. About the alpha channel, have you passed SpriteFlags.AlphaBlend to Sprite.Begin()?

Share on other sites
Yep, everything works fine if I don't use that extended function overload. (with the exception of stretching)

Share on other sites
what is your display format? I'd bet it's something like X8R8G8B8 (if you're running 32-bit color) which ignores the highest bits, rather than interpreting them as an alpha channel. If you create a surface with that format, I think D3D will ignore that data, losing the transparency information. If your display format is X8R8G8B8, you should pass A8R8G8B8 instead of the display format.

Share on other sites
I love you, it worked, lol

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• Forum Statistics

• Total Topics
628327
• Total Posts
2982089

• 22
• 9
• 9
• 13
• 11