Jump to content
  • Advertisement
Sign in to follow this  
lodoss118

anti alaising effect on sprites?

This topic is 4271 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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;
}


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!