Sign in to follow this  
lodoss118

anti alaising effect on sprites?

Recommended Posts

lodoss118    102
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
kovacsp    306
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
lodoss118    102
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
Sc4Freak    643
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
lodoss118    102
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
lodoss118    102
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
Toolmaker    967
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
Evil Steve    2017
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
Mirate    122
Antialiasing is disabled by default in direct3d, so unless you have your presentation parameters set to use multisampling, then antialiasing is not applied, if you do on the otherhand, simply use :

d3dDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, FALSE);

right before rendering anything you DONT want antialiased, just remember that if there are things that you do want aa, then set it to true when your done.

Share this post


Link to post
Share on other sites
JBourrie    1204
If you have a more recent video card, you might have the drivers set to automatically antialias DirectX programs. If you're using an ATI card, open the Catalyst Control Center. Theres something similar for NVidia cards but I don't know what it is.

Share this post


Link to post
Share on other sites
Sc4Freak    643
Quote:
Original post by lodoss118
hi wat i am trying to do, is to disable the anti alaising effect not add one?

The pictures you posted show no antialiasing whatsoever. In fact, the images are extremely aliased with large jagged edges.

I'm not sure what you're asking here, could you clarify?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
uhm wat i was trying to do is get that old school look from the sprites

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by lodoss118
uhm wat i was trying to do is get that old school look from the sprites
The screenshots you post seem to have that already. It's just not that obvious because you're not scaling them much. Try scaling the sprites 4x or 6x and you'll really notice the difference in filtering modes.

Share this post


Link to post
Share on other sites
OrangyTang    1298
This is just a guess, but is your sprite power-of-two in size (eg. 32x32, 64x128, 512x256, etc. etc)? If it's not then you may find it's being resized to power-of-two beind your back without you knowing (which would use some kind of scale/filter to resize it).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this