Jump to content
  • Advertisement
Sign in to follow this  
Blodyavenger

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

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

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
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 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
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!