• Advertisement
Sign in to follow this  

Loaded texture is blurred?

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

What I did is loaded a tga file and make it as a texture and then use that texture to be drawn on the screen. The problem I'm having is as if antialiasing was on and it doesn't look crisp. Anyway, I uploaded the files here I don't think there is a problem with loading the TGA file because I used one of the examples on gamdev and I figured if there was a problem, it wouldn't be reported already. This is a comparison of what it looks like and what I was expecting it to look like.

Share this post


Link to post
Share on other sites
Advertisement
Probably you are using an interpolation filter. Try to remove it


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_NEAREST);



Another tip: your mapped quads (the card) should be of the same dimension of the (sub)image you use.

Share this post


Link to post
Share on other sites
Your textures are not powers of two (in dimension). Who knows what opengl is doing to them in order to make them so.

I found this here:
Quote:

Initially, the width and height of data are checked to see if they are a power of two. If not, a copy of data (not data), is scaled up or down to the nearest power of two. This copy will be used for subsequent mipmapping operations described below. (If width or height is exactly between powers of 2, then the copy of data will scale upwards.) For example, if width is 57 and height is 23 then a copy of data will scale up to 64 in width and down to 16 in depth, before mipmapping takes place.

Given that your card texture is 71x96, it is probably being scaled to 64x64, losing lots of detail in the process. Either don't use gluBuild2dMipmaps, or manually scale your images UP to 128x128.

Share this post


Link to post
Share on other sites
Well, all the cards are in one file, so I have to resize the whole file to a power of 2. I guess this is improving the quality of the card. I guess I miss read multiple of 2 before instead of power of 2.

Thanks

Share this post


Link to post
Share on other sites
Still doesn't look like it should.
The tga file is 512x2048 which are powers of 2.

Share this post


Link to post
Share on other sites
Quote:
Original post by nprz
Still doesn't look like it should.
The tga file is 512x2048 which are powers of 2.


The dimensions must be equal in size and a power of 2. (Eg. 512x512, 256x256, etc)

I'm sure that I can already hear the resounding groan of agony coming from over there. :)

Share this post


Link to post
Share on other sites
You bet I'm groaning. It makes me want to use an engine that does all this for me. Oh well, I think I can fix that problem fairly easily, thank you.

-edit- It looks more blurry as 2048x2048. Any other suggestions? :)

Share this post


Link to post
Share on other sites
errm, no.
OpenGL textures can be any power of two in any direction, so his texture sizes are valid.

the problem is mapping the texels to the screen, which is whats causing the bluring, try offseting your texture coords by 0.5 (or 0.05.. some small number with a 5 in anyways) in each direction (cant recall off hand if its positive or negative either) and that should help line up texel centers with pixel centers

Share this post


Link to post
Share on other sites
offsetting the TexCoord by 0.05 or any amount will just move what part of the texture is displayed. and changing the Vertex will just move where it is displayed.

Can anyone recommend any files to load BMP as a texture, so I can at least try that?

Share this post


Link to post
Share on other sites
Quote:
Original post by _the_phantom_
errm, no.
OpenGL textures can be any power of two in any direction, so his texture sizes are valid.


Gah, are you serious? I've been misinformed then. Many apologies nprz for this unintentionally misleading information. :/

Share this post


Link to post
Share on other sites
Quote:
Original post by nprz
offsetting the TexCoord by 0.05 or any amount will just move what part of the texture is displayed. and changing the Vertex will just move where it is displayed.


aha! I knew I wasnt going crazy;
This talks about what I was waffling on about.
Granted, the answer assumes you are using a texture of the right size, but in your case the jitter should be 1/<texture width> across and 1/<texture height> down, that might fix the problem.

Really, to get proper texel=>pixel alignment you'll want the cards to be proper size and then set the 2D Ortho projection so that it 0=><card width> will give you the correct size card for pixel perfect drawing, then the texture sample jitter should make any issues go away.


Quote:

Can anyone recommend any files to load BMP as a texture, so I can at least try that?


I'm betting it wont matter.
Your suffering from the fact that texels arent sampled in the centre but at the edges, so when you ask for 1,1 you infact get a sample of a few pixels in the area to build that texel.

So, my advise, make each card proper size, set up a 2D Matrix so each card will be drawn proper size and then jitter the U,V coords slightly to get around the off center sampling.

[Edited by - _the_phantom_ on January 4, 2005 11:01:57 PM]

Share this post


Link to post
Share on other sites
Thanks for that link. I read it and noticed this

"Update: It looks like this problem might be due to invariance in texture filtering, as allowed by the OpenGL spec. The blur manifests differently on different GPUs."

This let me to test it on my dad's computer and it displays it correctly. I guess my card doesn't behave well with OpenGL.

I still don't know of a generic way to fix it, so maybe I should use SDL or something else for this card game.

Share this post


Link to post
Share on other sites
Perhaps you've got anti-aliasing set by the driver on your machine? Go to your 'display properties' > 'settings' > 'advanced' (or something like that) to check :)

Share this post


Link to post
Share on other sites
One way to make it all go away is to just use a 2D api (sdl like you said? I'm not positive what its capabilities are). This game doesn't look very 3d.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement