PDA

View Full Version : Animated sprite texture bleeding. (DX9, C++)


poita
04-23-2006, 02:14 AM
Ok, so I'm loading an animated bitmap using D3DXCreateTextureFromFileEx and creating a sprite that will use the texture. The bitmap is 48x48 and split into 4 frames of 24x24.

Note: I load the texture with filters (D3DX_FILTER_MIRROR || D3DX_FILTER_NONE).

Now when I draw a frame from the texture using the sprite and the required source RECT, I'm getting some 'bleeding' (right word?) from the other frames (At the edge of the sprite I can see pixels from the other frames).

I understand that I wouldn't get this if the bitmap wasn't split into frames because D3DX_FILTER_MIRROR doesn't wrap the U-V coordinates. How can I get it so that it doesn't read from outside my source rect for that frame?

If I didn't explain that well then just let me know and I'll try harder :wacko:

Thanks in advance, :yes:

juhnu
04-23-2006, 04:12 AM
Disable texture filtering and be careful with the texel sampling or a better way would be to leave few texel wide borders between frames. Remember to disable mipmapping as well.

poita
04-23-2006, 07:26 AM
Disable texture filtering and be careful with the texel sampling or a better way would be to leave few texel wide borders between frames. Remember to disable mipmapping as well.

Doesn't D3DX_FILTER_NONE disable texture filtering? And what do you mean by being careful with texel sampling? (I'm a bit new to programming with DirectX, not up with the lingo yet :) )

Yeah, leaving a border between frames would work, it's just that I would like a more 'elegant' way of doing it. :geek:

juhnu
04-23-2006, 07:59 AM
Doesn't D3DX_FILTER_NONE disable texture filtering? And what do you mean by being careful with texel sampling? (I'm a bit new to programming with DirectX, not up with the lingo yet :) )

Yeah, leaving a border between frames would work, it's just that I would like a more 'elegant' way of doing it. :geek:

I should have been more elaborate I think. With the texture filtering I meant the filtering which is done when a texel is sampled. It's a sampler state, which can be set using the method IDirect3DDevice9::SetSamplerState(). The filtering enum you give to the d3dx texture loading function has nothing to do with this, but affects how a texture is resampled loading time if needed(if you have forced a specific texture size or the mipmap generation.)

If you use a point filtering (taking the nearest texel) you could survive without making borders in theory, but I think it's not really worth the trouble.

Check this if you want to know better about the texture sampling rules:
http://www.paradoxalpress.com/Docs/DX9_out/Nearest_Point_Sampling.htm

However, I would recommend you to use borders around sprites It's a common and tested way to solve this problem. Also sprites would probably look much better when you can use the bilinear filtering.

poita
04-23-2006, 09:10 AM
Thanks a lot. I'll look into those. I'll probably get round to it tomorrow and post the results.

Thanks again