Sign in to follow this  

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

This topic is 2952 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

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!

Share this post


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


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


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


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


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

Share this post


Link to post
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 sprites

d3dspt->End();

Share this post


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


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


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


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


Link to post
Share on other sites

This topic is 2952 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.

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