[.net] Stretched D3DX Sprite

Started by
17 comments, last by Uphoreum 17 years, 6 months ago
Quote:Original post by Uphoreum
Wow, 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.
Advertisement
Wow, so much to think about!
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?
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.FromFile
A 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.
What should I set that parameter to?

How can I tell if my device format supports an alpha channel?
Quote:Original post by Uphoreum
What 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()?
Yep, everything works fine if I don't use that extended function overload. (with the exception of stretching)
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.
I love you, it worked, lol

This topic is closed to new replies.

Advertisement