Textures are blurry

Started by
5 comments, last by Myopic Rhino 18 years, 11 months ago
Here is how I load each of the textures:

            glGenTextures(1, &brTex[idx]);
            
            glBindTexture(GL_TEXTURE_2D, brTex[idx]);
            
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
            
            gluBuild2DMipmaps(GL_TEXTURE_2D, 3, btextures[idx]->w, btextures[idx]->h, GL_BGR, 
                              GL_UNSIGNED_BYTE, btextures[idx]->pixels );



Each texture is 80 x 20 pixels and thats also the size I make each rectangle, (2d game using ortho2d()) which I apply the texture too. Also I have blending enabled which I initialized with this code: glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); That's about it. The only problem I'm having is that the textures appear blurry, I also used another library besides OpenGl for the game and they looked just fine.
Advertisement
yea mipmaps blurred my images as well. The exact reason I forget right now, but it has something to do with just making a resized copy of the image I think.
Anywho, use
glTexImage2D();

but the textures aren't a power of two.
OpenGL can only do power-of-two texture sizes (128x32, 64x64 etc.) unless you use extensions. gluBuild2dmipmaps will automagically resize your texture to the nearest valid size and rescale your image to fit (which introduces the blurring).

Either:
- use correctly sized textures in the first place
- create textures larger than needed and mess with the texture coords to get the correct subregion
- use an extension to load oddly sized textures
I wan't to go with the extension option but I don't know anything about extensions. Can anyone give me a link or explain how to use an extension?
You dont have to enable any extensions to use non power of 2 textures. Yes it is an extension, but if the extension exists it simply works. Now, the thing is, hardly any video cards support non-power-of-2 textures. Stick with power-of-2 textures and never, ever let gluBuild2DMipmaps resize a non-power-of-2 texture (its buggy as hell and only results in data loss).
gluBuild2DMipmaps is going to stretch an 80x20 texture to 128x32. That's probably the source of most of your blurring. The rest is the choice of filtering, since it's going to apply a box filter to the texels. For 2D you're going to adjust your textures offline to be power of two and use GL_NEAREST filtering.

This topic is closed to new replies.

Advertisement