Sign in to follow this  
Uphoreum

[.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 this post


Link to post
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 this post


Link to post
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 this post


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

Share this post


Link to post
Share on other sites
Yep,
Device:


//Setup Presentation Perameters
PresentParameters Parameters = new PresentParameters();

//One Back Buffer
Parameters.BackBufferCount = 1;

//Set Our Window As Device's Window
Parameters.DeviceWindow = Window;

//No V-Sync
Parameters.PresentationInterval = PresentInterval.Immediate;

//Discard Old frames
Parameters.SwapEffect = SwapEffect.Discard;

//Set As Windowed
Parameters.Windowed = true;

//Create The Device
Device Device = new Device(0, DeviceType.Hardware, Window, CreateFlags.SoftwareVertexProcessing, Parameters);



Texture:

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


Share this post


Link to post
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 this post


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

Share this post


Link to post
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 this post


Link to post
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.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.

Share this post


Link to post
Share on other sites
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()?

Share this post


Link to post
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 this post


Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this