I am using the October 2005 Release of DirectX 9.0. When attempting to Scale a Sprite I am running into some very odd behavior. When "growing" the Sprite the Texture stretches and maps fine. When "Shrinking" the Sprite the texture apparently does not shrink - and it gets cut off.
I am setting the Transform properly on the Sprite, applying SpriteFlags.AlphaBlend to Sprite.Begin(), and using Sprite.Draw().
Is anyone else having this problem

Scaling (Shrinking) Sprite Chops Off Texture...
lozinski
Sounds like you're not using a mipmapped texture. Try either setting the D3DSAMP_MIPFILTER sampler state to D3DTEXF_NONE before calling Draw(), or generating the mipmap chain when you load the texture.
lfox
Thats pretty much the same result that I am getting. Very odd.
I have tried upgrading to the latest release of the SDK (February 2006) - but the problem still persists.
I am using C# and the Managed DirectX Libraries. If you'd like I can upload some source.
RMarar
Admittedly I don't tend to use the sprite interface, but from the descriptions so far it doesn't sound like it should be normal behaviour...
Posting the relevant code fragments might be useful - if you are doing something wrong then someone might be able to spot it...
Might be a good idea to send this off to the directx team - directx@microsoft.com, if it is a bug then a test-case and repro code will be useful to them.However, it'd be best to check it on the latest-n-greatest SDK first. The sprite interface is part of D3DX rather than the core D3D runtime. I'm pretty sure there's been an update to D3DX since the October release (iirc, there wasn't any changes in the Dec '05 SDK though). If it does prove to be a genuine bug then they'll probably be able to fix it for a future SDK update.
hth
Jack
kevin mcaleer
This would fix the fading and fuzziness when the texture is scaled - but it does not explain why the texture is getting chopped off.
Pharvana
Thanks to the post about mipmapping above I was able to fix the problem. I was actually using a full range of mipmapping for all my textures, when I should have just used one mipmap level. Setting mipmap levels to 1 removed the problem I was having.
Thanks a lot! :)
MikeyG99
I did the test case by modifying code in a larger project, and fishing out only the relevant bits of code from it is more than I'm able to handle, at least this week. For now, here's the actual rendering part of the sprite handling code. I'm 100% certain that the actual scaling numbers are correct, so there problem doesn't lie there. I'm doing lots of rendering which works very well with the code below, it's just for the downscaling that it doesn't work as it should.
if( ( texture != NULL ) && ( _sprite != NULL ) ){
D3DXMATRIX mat;
D3DXMatrixTransformation2D( &mat,
NULL,
0,
texture->getScaling(),
texture->getRotationCenter(),
texture->getRotation(),
texture->getTranslation() );
_sprite->Begin( 0 );
_sprite->SetTransform( &mat );
HRESULT result = _sprite->Draw( texture->getTexture(),
texture->getRect(),
NULL,
NULL,
texture->getColor() );
_sprite->End();
return result;}
By the way, I'm using the February version of the SDK.
Telesto
Bingo!
Thanks, Espen and Ross. Setting MipLevel to 1 when loading the Texture worked like a charm.
mallamahesh
Funny you should mention it. I was going to post a thread about the very same thing today.
I set up a test case in Direct3D using C++ to show an example of what's going on here. I've found no way to avoid this bug except to replace a texture with a premade smaller version of itself instead of scaling it down. Needless to say, that's a cumbersome solution, and I'd rather have the scaling working properly.
Here are the textures from the test:
1) This is the original, unscaled texture: http://www.medievalfuture.com/tilt/temp/wolf_1.png
2) Here I've scaled it down slightly. So far so good... http://www.medievalfuture.com/tilt/temp/wolf_2.png
3) Scaled down even more. Notice that the scaled version is now faded out slightly and being gradually replaced by a version of the texture that is bigger than the unscaled version. http://www.medievalfuture.com/tilt/temp/wolf_3.png
4) Scaled just a little bit more. The scaled texture has now been completely replaced by the inflated version, and the resulting texture becomes useless. http://www.medievalfuture.com/tilt/temp/wolf_4.png
Is this a known bug If it's caused by a bug in Direct3D, when can we expect a fix