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

Started by
13 comments, last by Erik Rufelt 14 years, 5 months ago
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: Angry face What could be wrong? Thanks for answers!
Advertisement
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.
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>
Use point filtering. Should solve your problem.
my blog contains ramblings and what I am up to programming wise.
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.
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
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.
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;
}


That's the code for loading texuters and to render sprite
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();
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);

This topic is closed to new replies.

Advertisement