DirectX texture loading, texture gets resized

DirectX texture loading, texture gets resized

Post by Marcel Ove » Fri, 18 Sep 2009 22:05:29

Hi all,

I was having problems with pixel-perfect collision detection...
(Oh no, not another pixel-perfect question! I hear you scream.)

.. and I solved it.
(you see, you didn't need to worry :))

But I don't understand why something is happening.

Using: .NET, C#
Microsoft.DirectX.Direct3D.Texture and

I have a windowed direct3d surface, 1024x768, 4 bytes per pixel

I load a texture from a smaller bmp which is 640x640 in size.
This bitmap contains blocks with sprite images.

I tried to do pixel checking against a background image using
LockRectangle and a double x/y loop, but somehow every sprite
got mangled. It seemed like no pixel was were it should be
except for the pixels on the first scanline.

The pixel tests on the background bitmap didn't have that problem.
Width=1024, 4 bytes per pixel, so each scanline was 4096 bytes.

Now it seems that the 640x640 bitmap is resized (not scaled) to
1024 by something. And because the background bitmap had the
exact same size as the device, at first, I didn't see that anything
could be wrong with the algorithm.

I guess this resized texture will take up more memory than is required.
Can this resizing 'feature' be turned off?
I've looked into the parameters of the sprite, texture and the
TextureLoader.LoadFromFile method, but I can't find anything to
change this behaviour.

And why is it happening in the first place?


DirectX texture loading, texture gets resized

Post by Marcel Ove » Sat, 19 Sep 2009 20:10:49

"Marcel Overweel" < XXXX@XXXXX.COM > schreef in bericht

Hehe, got it.
Textures get resized to a power of 2.
So 640 x 640 gets 1024 x 1024.
Have the original sprite bitmap resized to 512 x 512 and it stays 512.
I guess the reason for directx is some form of optimizations.