anti alaising effect on sprites?

Started by
16 comments, last by OrangyTang 17 years, 5 months ago
Hi i am using a directx wrapper that can render 2d sprites, for some reason they seem to be filtered like smoothed out, anti aliasing effect? While inspecting the load method for 2d sprites, i found this


DXUAPI BOOL DXULoadImage(LPDXUIMAGE image,TCHAR* file,DXUCOLOURKEY colourKey)
{
	image->lpPalette = NULL;

	if ( D3DXCreateTextureFromFileEx(lpd3dDevice,file,
		    D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,0,
		    D3DFMT_UNKNOWN,D3DPOOL_MANAGED,D3DX_FILTER_NONE,
		    D3DX_FILTER_NONE,colourKey,&image->info,
		    image->lpPalette,&image->lpTexture ) != D3D_OK )
			return FALSE;

	return TRUE;
}


I am pretty sure its one of the flags i have to change i don't want any filters on the image for drawing, anyone know what i have to change?
Advertisement
Hi,

one thing that can trick you is MIP-mapping. Use 1 as the fifth parameter instead of D3DX_DEFAULT.
Then, if bilinear filtering is switched on during you use the texture.
Check SetSamplerState(X, D3DSAMP_MAGFILTER, ...)and SetSamplerState(X, D3DSAMP_MINFILTER, ...) where you use the texture!

Hope this helps,
kp
------------------------------------------------------------Neo, the Matrix should be 16-byte aligned for better performance!
hi it doesn't work, it is still smoothed out(anti alaised) i was changing the parameters D3DX_FILTER_NONE with other tags such as D3DX_FILTER_POINT, but it seems that the sprite is out of its rect box, what i am trying to acheive is to not apply any effects so i can keep the original artwork, not that smoothed out effect i.e so it gets abit pixelated when scaled?

[Edited by - lodoss118 on November 9, 2006 2:43:32 AM]
You might be scaling the sprite incorrectly, if you minify or magnify the sprite the texture will no longer be exactly the same as the image you load in.

If you could post a screenshot, it might help diagnose the problem.
NextWar: The Quest for Earth available now for Windows Phone 7.
hi tell me if u can access these

http://hafeez.bulldoghome.com/pages/hafeez_bulldoghome_com/scale1.JPG

http://hafeez.bulldoghome.com/pages/hafeez_bulldoghome_com/scale2.JPG
heres the function for scaling a sprite

DXUAPI BOOL DXUScaleSprite(LPDXUSPRITE sprite,double sx,double sy){	if ( sprite->isMirrorLeft )		sprite->scale.x = -(float)sx;	else		sprite->scale.x = (float)sx;	if ( sprite->isMirrorTop )		sprite->scale.y = -(float)sy;	else		sprite->scale.y = (float)sy;		DXURotateSprite(sprite,sprite->rotation);	sprite->tw = (double)(sprite->srcRect.right - sprite->srcRect.left) * sx;	sprite->th = (double)(sprite->srcRect.bottom - sprite->srcRect.top) * sy;		return TRUE;}
Anti-aliasing probably isn't going to work on textures(Don't shoot me if I'm wrong), since the textures are enlarged, and therefor, pixelated.

I suggest you enlarge your textures manually using hq2x/hq3x/hq4x:
http://www.hiend3d.com/hq2x.html

Visit the see, and take a look at the 3rd test case, and you'll see how useful it should be in your case. You can always enlarge your sprites by 2, and scale them down to the proper size. Much better result.

Toolmaker

hi wat i am trying to do, is to disable the anti alaising effect not add one?
:'(
They look pretty jagged in your screenshot, although it might be hard to see because the second image isn't scaled up by much.

Have you definitely set the mag filter with SetSamplerState? That's what determines how to sample textures when they get scaled.

The following code should cause any magnification to use the nearest point, resulting in the jagged effect you want:
pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);


EDIT: Also, your D3DXCreateTextureFromFileEx() call is creating a full mipmap chain. If you're looking for "old school" graphics, you probably only want need mip level. To do that, change the third D3DX_DEFAULT to 1.

This topic is closed to new replies.

Advertisement