C++/VB - DirectX texture loading, texture gets resized

Asked By Marcel Overweel
17-Sep-09 09:05 AM
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 did not need to worry :))

But I do not understand why something is happening.

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

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 did not 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 did not 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 have looked into the parameters of the sprite, texture and the
TextureLoader.LoadFromFile method, but I cannot find anything to
change this behaviour.

And why is it happening in the first place?

regards,
Marcel
Microsoft.DirectX.Direct3D.Texture
(1)
Microsoft.DirectX.Direct3D.Sprite
(1)
TextureLoader.LoadFromFile
(1)
LockRectangle
(1)
DirectX
(1)
Textures
(1)
Hehe
(1)
Direct3d
(1)
  Marcel Overweel replied to Marcel Overweel
18-Sep-09 07:10 AM
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.

regards,
Marcel
help
is Microsoft.DirectX.Direct3D.Sprite obsolete? C++ / VB Hello, I found that there's no Sprite I can see when type a dot after Microsoft.DirectX.Direct3D. There was no Sprite datatype, so I wonder Microsoft.DirectX.Direct3D.Sprite is removed from MDX. I am using VS .NET 2005 and .NET framework 2.0