# Direct3D - I'm getting "blur" effect on pixelate GFX

## Recommended Posts

Blodyavenger    432
Sorry I didn't know how to name this topic better than that...ok, let's rather go into the problem right away. I'm juniour game programmer (directX) and I started my game with pixel art graphics but I have one problem here. Everything gets blured what I don't want because I lost "Pixel art" quality then and I don't have a single idea how to correct that. I'm adding an image of the problem: What could be wrong? Thanks for answers!

##### Share on other sites
Erik Rufelt    5901
How do you create your textures, and how do you draw them?
It looks as if you have textures not powers of 2, that are resized to powers of 2. Perhaps you are using D3DXCreateTextureFromFile?
For pixel-art something like the following is a good way to load textures:
D3DXCreateTextureFromFileEx(	pDevice,	TEXT("texture.png"),	D3DX_DEFAULT_NONPOW2,	D3DX_DEFAULT_NONPOW2,	1,	0,	D3DFMT_UNKNOWN,	D3DPOOL_DEFAULT,	D3DX_DEFAULT,	D3DX_DEFAULT,	0,	NULL,	NULL,	&pTexture);

Some blurring can also occur if you draw so that texels aren't exactly aligned to integer pixels on the screen. Coordinates are usually offset with 0.5 pixels in D3D9, so you might need to correct for that. It shouldn't give such a large blur as you have though, which is why I suspect the textures.

EDIT: Actually it doesn't look all that blurry.. so I would check the pixel offset. Try subtracting 0.5 from your texcoords or vertex positions.

##### Share on other sites
Blodyavenger    432
1.) I'm taking care that texutre sizes are the power of 2
2.) I was using the same function for using textures but with a bit
different parameters, but I tried yours and it's still not working.

3.) <shrugs>

##### Share on other sites
Imgelling    222
Use point filtering. Should solve your problem.

##### Share on other sites
Erik Rufelt    5901
Do you offset your vertices with half a pixel, or are you using the sprite interface or how are you drawing?
If you want to draw an image with a dimension of 100, it should be drawn from -0.5 to 99.5.

##### Share on other sites
Blodyavenger    432
Hmm...can I get a small help with that? Where do I enable that? Or is it a bit more behind it than "Just enable it"?

EDIT: I'm drawing in 2D mode - sprites

##### Share on other sites
Erik Rufelt    5901
Then you shouldn't need it, but draw at exact positions. Are you using transform matrices?
Try drawing without any transform to make sure the images are drawing correctly.

EDIT: You need to make sure your matrix only translates exact integer pixel offsets. You can use floor(float_value) for that, when constructing your matrix with for example D3DXMatrixTranslation.

##### Share on other sites
Blodyavenger    432
Ok, the thing is that I'm not using vertices and matrices, just pure
sprites:

Quote:
 void LoadSprite(SPRITE* pSprite, LPCTSTR File, int width, int height, int cols, int rows){ D3DXCreateTextureFromFileEx(d3ddev, File, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, D3DCOLOR_XRGB(255, 0, 255), NULL, NULL, &pSprite->tex); return;}

Quote:
 void DrawSprite(SPRITE* pSprite, int left, int top, int width, int height, int x, int y){ RECT FrameBox; FrameBox.left = left; FrameBox.top = top; FrameBox.right = left +width; FrameBox.bottom = top + height; D3DXVECTOR3 position(x*1.0f, y*1.0f, 0.0f); d3dspt->Draw(pSprite->tex, &FrameBox, NULL, &position, D3DCOLOR_XRGB(255, 255, 255)); return;}

##### Share on other sites
Calling ID3DXSprite::Begin() changes various render states (see http://msdn.microsoft.com/en-us/library/ee421547%28VS.85%29.aspx for details). You can change them back if you need to.

I'd suggest doing something like this:

d3dspt->Begin();d3ddev->SetTextureStageState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);d3ddev->SetTextureStageState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);d3ddev->SetTextureStageState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);// Draw all the spritesd3dspt->End();

##### Share on other sites
Blodyavenger    432
That's what I did after d3dspt->Begin()
but it's still happening (blur effect)

d3ddev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);d3ddev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);d3ddev->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);

##### Share on other sites
Erik Rufelt    5901
There's a problem in the D3DXCreateTextureFromFileEx you posted, are you sure you tried the flags I posted?
You need to specify D3DX_DEFAULT_NONPOW2 to the two arguments after the file-name, which isn't present in the one you posted. Try changing D3DX_DEFAULT to D3DX_DEFAULT_NONPOW2, as follows:
Quote:
 void LoadSprite(SPRITE* pSprite, LPCTSTR File, int width, int height, int cols, int rows){D3DXCreateTextureFromFileEx(d3ddev,File,D3DX_DEFAULT_NONPOW2,D3DX_DEFAULT_NONPOW2,0,NULL,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,D3DCOLOR_XRGB(255, 0, 255),NULL,NULL,&pSprite->tex);return;}

##### Share on other sites
Blodyavenger    432
Like I said, I tried that but it's not working. And I tried again now and it's still not working

##### Share on other sites
Erik Rufelt    5901
I pasted the exact code you posted into my own project, and they work for me, with no blurring, if I change to load non power of 2 textures (I don't touch the sampling either, as it has no meaning when doing 1:1 scale drawing). So the problem is probably somewhere else. How do you create your device?
Perhaps your back-buffer has a different size than your window, so the blurring isn't with the sprites at all. Try drawing some text with an LPD3DXFONT and see if that is also blurred.

##### Share on other sites
Blodyavenger    432
Oh my...actually I found the problem and it was a stupid one:

I had forced anti-analizing in my nVidia settings and that was the
problem but your code is working now, thanks a lot for your nerves
and that you actually took time for me.

I appreciate it a lot!

##### Share on other sites
Erik Rufelt    5901
As usual, the longer it takes to find a problem, the simpler the solution. =)

## Create an account

Register a new account