Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » DirectX: Crusty lines around sprites

This thread is locked; no one can reply to it. rss feed Print
DirectX: Crusty lines around sprites
Kris Allen
Member #4,639
May 2004
avatar

Hi... this is a proper question this time, not a stupid mistake like my last post :P

I'm using the ID3DXSprite interface to draw sprites. Loading a texture is fine, as well as preparing and drawing the sprite. The problem is that there's a horrible blurry outline around my sprites that I can't get rid of.

Here's my source image (x2):

http://kris.acsv.net/hello_1.gif

And here's what it looks like onscreen:

http://kris.acsv.net/hello_2.gif

Here's my code, with irrelevant bits cut out:

1 
2ID3DXSprite * sprite1;
3IDirect3DTexture9 * texture1;
4 
5//---------------
6 
7result = D3DXCreateSprite(d3d_device,&sprite1);
8 
9result = D3DXCreateTextureFromFileEx(d3d_device,
10 "image.bmp",
11 D3DX_DEFAULT,
12 D3DX_DEFAULT,
13 1, // don't use mip maps
14 D3DUSAGE_RENDERTARGET,
15 D3DFMT_UNKNOWN,
16 D3DPOOL_DEFAULT,
17 D3DX_FILTER_NONE, // filter
18 D3DX_FILTER_NONE, // Mip (?) filter
19 0x00FF00FF,
20 NULL,
21 NULL,
22 &texture1);
23 
24 
25//---- INSIDE MAIN LOOP
26 
27d3d_device->Clear(0,0,D3DCLEAR_TARGET,0xFF0000,0,0);
28
29d3d_device->BeginScene();
30 
31//-----------------
32
33sprite1->Begin(D3DXSPRITE_ALPHABLEND);
34
35sprite1->Draw(texture1,
36 0, // show the whole image
37 0, // Top-left is centre
38 &D3DXVECTOR3(50,50,0),
39 0xFFFFFFFF); // Keep original colour etc
40
41sprite1->End();
42
43//-----------------
44 
45d3d_device->EndScene();
46 
47d3d_device->Present(0,0,0,0);


What's causing this? Is it some sort of filter, or is it due to my sprites being textures? How on Earth do I get rid of it?

EDIT: This also happens if I have masking / alpha turned OFF, so I'm pretty sure it's nothing to do with that.

Thanks!!

- Kris

DanielH
Member #934
January 2001
avatar

Anti-Aliasing? Sorry, don't know DirectX3D.

Steve Terry
Member #1,989
March 2002
avatar

sprite1->Begin(D3DXSPRITE_ALPHABLEND);
you are telling it to alpha blend... perhaps that is causing teh aliasing?
check and make sure you don't have antialiasing on either in your video card settings.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Marco Radaelli
Member #3,028
December 2002
avatar

I do not know DX, but that image looks antialiased to me too :)

[edit] Steve may have a good point:

The DirectX SDK said:

D3DXSPRITE_ALPHABLEND: Enables alpha blending with D3DRS_ALPHATESTENABLE set to TRUE (for nonzero alpha). D3DBLEND_SRCALPHA will be the source blend state, and D3DBLEND_INVSRCALPHA will be the destination blend state in calls to IDirect3DDevice9::SetRenderState. See Alpha Blending State. ID3DXFont expects this flag to be set when drawing text.

Kris Allen
Member #4,639
May 2004
avatar

Surely it's not a video card thing alone?? There's got to be an option to turn it off per-app...

edit: Actually, thanks Marco & Steve, that sounds like what I want... now I just need to figure out how to set the options that it specifies

edit 2: aha, think I've got it

edit 3: nope :-/

- Kris

Steve Terry
Member #1,989
March 2002
avatar

There is no way to stop someone from telling all D3D apps to use anti-aliasing, you can always force. You can disable it in D3D though, just it can be overridden.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Kris Allen
Member #4,639
May 2004
avatar

Well, that's fine really. I never use anti-alias myself personally and I think it looks horrible in 2D games :S

I've tried adding this code:

d3d_device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);
d3d_device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ZERO);

Which supposedly disables "texture blending", but I haven't noticed any difference.

Oh, actually I don't think that's even what I need to change

- Kris

Oscar Giner
Member #2,207
April 2002
avatar

I don't think that has anything to do with antialiasing. At least with nvidia cards, antialiasing is only applied to polygon edges (just turn on AA on any game and look at textures with alpha channel, like fences. They aren't antialiased).

A little of googling showed me that ID3DXSprite just draws polygons with a texture, so the power of 2 restriction in the texture dimensions still applies. So this may be caused because your sprites are automatically stretched so they have power of two dimensions.

Kris Allen
Member #4,639
May 2004
avatar

It's already a power of 2 :( the whole image is 128x128

- Kris

MickyD
Member #2,409
June 2002

I don't know much about this stuff, but if you are trying to get it to display with some kind of transparency (like a sprite) then I think the image you use has to have at least a one pixel transparency box around it. So in an image editing program up your image size by 2 on the x and y. Make the newly added blank pixels be whatever you use for transparency. If you are using any kind of scaling or rotation I think you have to do this.

gillius
Member #119
April 2000

None of these people are right. The problem is because of texture filtering. You need to change to point sample to get a "pixelated" image, but then you end up with crappy looking graphics, unless you are really going for the retro look, which has very high-contrast lines that need to be preserved, and you are guaranteed to always have a 1:1 ratio on the screen (ie you aren't scaling the image).

With scaling you want to consider trilinear filter (or bilinear and force mipmaps to be off). If you are using photo-realistic images you really want trilinear filtering. Anisotropic filtering is completely usless in a 2D game, because all of the images are drawn completely 100% isotropically (facing the camera).

Gillius
Gillius's Programming -- https://gillius.org/

Kris Allen
Member #4,639
May 2004
avatar

Ahh I see. Well, I've tried adding these lines:

d3d_device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_NONE);
d3d_device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_NONE);
d3d_device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
d3d_device->SetSamplerState(0, D3DSAMP_MIPMAPLODBIAS,0);

But they still don't seem to make any difference. Am I still missing something?

And yep, I'm trying to get the retro look ;D I hate these blurry graphics, to be quite honest

Edit: Weird, turns out that onscreen my sprite is only 127x121 pixels. I wonder why that's happening...

Edit 2: Ok, turns out to be a DirectX problem...? (Why am I not suprised?) That still doesn't quite seem to explain how to fix it - I've tried the +1/-1 thing but it's still way too small.

- Kris

Go to: