Sign in to follow this  
cppcdr

Fuzzy images?

Recommended Posts

I am trying to load a texture from a file using the D3DXCreateTextureFromFileEx () function. It works, but my images are fuzzy. I would like to be able to see the actual pixels instead of a blurry image. Anyone know why it is blurry?

Share this post


Link to post
Share on other sites
What dimensions are the image - both in the original file, in memory and how its rendered.

If you try to load non-2n dimension images into Direct3D it will sometimes (depending on flags and HW) resize it to the nearest 2n dimension. This can introduce some blurriness.

You can verify this by calling IDirect3DTexture9::GetLevelDesc(0, ...) to see what dimension it exists in memory. You can also use D3DXGetImageInfoFromFile() to check what dimensions its stored as.

When it comes to rendering there are two possible problems:

1. You're not following the "Directly Mapping Texels to Pixels" guideline (see docs for an article of the same name).

2. You're not rendering it exactly the same size, at which point the filtering mode you've selected (e.g. Linear, Anisotropic..) is re-sampling it from the stored dimensions to the rendered dimensions.

hth
Jack

Share this post


Link to post
Share on other sites
My texture is a 16x16 bmp (for testing) and I am rendering it to a 16x16 square.
Are there any flags that make this blurriness possible? Mayby I set one without thinking...

Share this post


Link to post
Share on other sites
Did you check this suggestion out:
Quote:
1. You're not following the "Directly Mapping Texels to Pixels" guideline (see docs for an article of the same name).

??

What texture and position coordinates are you using?

Jack

Share this post


Link to post
Share on other sites
Yes I read the article. I didn't understand all of it, but I got the thing about texture coords not being placed correctly at the corners...

But it's not just the corners that are blurred, it's my whole image.

As for the texture and pos coords, I have 4 verts with texture coords (x, y, z, u, v) that are respectively (0, 0, 0, 0, 0) (0, -5, 0, 0, 1) (5, 0, 0, 1, 0) (5, -5, 0, 1, 1).

Share this post


Link to post
Share on other sites
If the corners are not aligned, then the other pixels are not aligned as well. You must really make sure that all the pixels are being matched perfectly.

Anyway, you should disable texture filters (Linear, Anisotropic, etc) if you're not going to be using them.

Share this post


Link to post
Share on other sites
Your texture coordinates do not follow the results of that article, and I would put money on that being the reason you get blurry results [smile]

Offset by 0.5/width and 0.5/height respectively.

hth
Jack

Share this post


Link to post
Share on other sites
I have changed the texture coords, and I have not gotten better results (mayby a little better, but not much).
Here are the new coords (0, 0, 0, -0.5/1024, -0.5 / 768) (0, -5, 0, -0.5/1024, 1-0.5/768) (5, 0, 0, 1-0.5/1024, -0.5 / 768) (5, -5, 0, 1-0.5/1024, 1-0.5/768).


Here are some photos that show the problem (I am comparing to maya because I am making a modeler)...
My version
Maya's version

Share this post


Link to post
Share on other sites
hmm, somethings not making sense here...

Your image looks more like something to do with linear filtering..

Quote:
I have 4 verts with texture coords (x, y, z, u, v) that are respectively (0, 0, 0, 0, 0) (0, -5, 0, 0, 1) (5, 0, 0, 1, 0) (5, -5, 0, 1, 1).
So you're specifying your vertex positions in 3D space - not pre-transformed? And you're defining a 10x10 grid (-5..+5) for a 16x16 texture.

How are you making sure that the final rasterized results are a 1:1 mapping? Even if your texture coordinates are correct, if the final rasterized quad is not a 1:1 (16x16 in this case) area then you'll get stretching that'll get smoothed out by the linear filtering.

Try setting it to POINT filtering.

hth
Jack

Share this post


Link to post
Share on other sites
D3DXCreateTextureFromFileEx(g_App.GetDevice(), //device
"leaf.png", //file name
D3DX_DEFAULT, //width
D3DX_DEFAULT, //height
D3DX_DEFAULT, //mip levels
NULL, //usage
D3DFMT_UNKNOWN, //texture color format
D3DPOOL_MANAGED, //memory class
D3DX_FILTER_NONE, //filter ----------------------[important]
D3DX_FILTER_NONE, //mip filter ----------------------[important]
0, //no color key (NEW)
NULL, //source info
NULL, //pallette
&pLeafTexture); //texture object

Modified copy of the code, here.


This would work in my days..

Share this post


Link to post
Share on other sites
Ok, I have changed the min and mag filters to D3DTEXF_POINT. The image is a LOT better. There is still a little problem because the image get's blurry very quickly when I zoom out, but it doesn't matter too much...

Anyway, thank you everyone for helping!

Share this post


Link to post
Share on other sites
Try offseting the u, v by 0.5/width or 0.5/height,
setting the x, y to the same of texture size,
and setting the filter to D3DTEXF_LINEAR,
then you can get a sharp image with smooth zooming.
I came into the same problem of you and resolved by that.

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