![]() |
|
DirectX: Crusty lines around sprites |
Kris Allen
Member #4,639
May 2004
![]() |
Hi... this is a proper question this time, not a stupid mistake like my last post 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:
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
![]() |
Anti-Aliasing? Sorry, don't know DirectX3D. |
Steve Terry
Member #1,989
March 2002
![]() |
sprite1->Begin(D3DXSPRITE_ALPHABLEND); ___________________________________ |
Marco Radaelli
Member #3,028
December 2002
![]() |
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
![]() |
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
![]() |
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. ___________________________________ |
Kris Allen
Member #4,639
May 2004
![]() |
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
![]() |
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
![]() |
It's already a power of 2 - 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 |
Kris Allen
Member #4,639
May 2004
![]() |
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 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 |
|