• Advertisement
Sign in to follow this  

[SlimDX] Sprite pixel/texel scaling?

This topic is 3389 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For a while, I was drawing a sprite using a System.Drawing.Image to draw directly onto a PictureBox control. Now, I'm trying to port the same functionality into a Direct3D instance and draw it from a SlimDX.Direct3D9.Texture. The code bits for calculating the source sub-rectangle and the destination draw rect are identical in both cases, but the end result is different: It kinda looks like the SlimDX version is drawing with some kind of pixel/texel translation that's not 1:1... if that even makes sense (which it probably doesn't). I poked around a bit but didn't find anything that seemed relevant. FWIW, I'm using the SlimDX.Direct3D9.Sprite class to draw the sprite. Any ideas? I'm hoping it's just something obvious that I've blindly overlooked. :P (BTW that sprite isn't actually mine, it's from some random spritesheet I grabbed off Google image search just for testing.)

Share this post


Link to post
Share on other sites
Advertisement
It's hard to tell without seeing any source. Try posting the loading and drawing code, using the [ source ] tags to make it all look pretty. We should be able to see if you're doing anything obviously wrong.

Share this post


Link to post
Share on other sites
Sounds suspiciously like the texture dimensions are not matching the image size. That's a general problem when you come from a software 2d architecture to 3d.

Most 3d cards prefer image sizes with powers of 2. A lot are able to deal with odd sizes but some can't.

Check the texture dimensions once the image is loaded in there. It will most likely not match the image size. You have to take this in account in the drawing code.

Share this post


Link to post
Share on other sites
In particular, D3DX has a tendency to change images to power of 2 sizes if you don't get the flags right.

Share this post


Link to post
Share on other sites
Quote:
Original post by Endurion
Most 3d cards prefer image sizes with powers of 2. A lot are able to deal with odd sizes but some can't.


Ugh. I knew this. Why didn't I think to check it?

That was exactly the problem. Expanding my test texture to power-of-2 dimensions produced the result I was looking for.

It's interesting that my non-power-of-2 texture was automatically scaled up at load-time. Did SlimDX do that, or my graphics card? I used the Texture.FromFile method to load the texture.

It's no big deal for me to make sure my texture dimensions are powers of 2. But I wonder if there's a more graceful way I can handle this, other than just checking the post-load dimensions and throwing an exception if they're not correct?

Share this post


Link to post
Share on other sites
DirectX (more specifically the D3DX function SlimDX calls under the hood) did it. There are flags you can pass to the load methods to avoid the scaling, if your card supports it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement