[SlimDX] Sprite pixel/texel scaling?

Started by
4 comments, last by jpetrie 15 years, 3 months ago
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.)
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.
Mike Popoloski | Journal | SlimDX
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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

In particular, D3DX has a tendency to change images to power of 2 sizes if you don't get the flags right.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
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?
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.

This topic is closed to new replies.

Advertisement