PDA

View Full Version : Changing texture filtering on the fly?



07-23-2006, 11:23 AM
How can I change texture filtering on the fly? Do I actually got to re-load my textures and change the filtering at that moment?.

Also, I have another question (regarding tex filtering as well).


I found this code:


witch (filt) {
case POINT:/* point sampling of nearest neighbor */
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
break;
case BILINEAR:/* bilinear interpolation */
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
break;
case TRILINEAR:/* trilinear interpolation on pyramid */
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR);
break;
}


Is it ok?, or theres something wrong with the settings?. I need linear, bilinear and trilinear filtering.

Although what I care most right now, is how to change the filtering on the fly.


Thanks in advance.

memfr0b
07-23-2006, 12:41 PM
The code is perfectly fine. You can change the minifacation/magnification settings (almost) any time you like. They will stay until you change them again.

The only thing you have to keep in mind is that GL_*_MIPMAP_* needs all mipmap levels defined. So you can only activate trilinear filtering when your texture actually has mipmaps.

V-man
07-23-2006, 12:48 PM
No, there is no need to reload a texture.
Be sure to call glBindTexture before making those GL calls because the settings are part of the texture object.

Those are the definitions for POINT, BILINEAR. I'm not sure about trilinear because it could be
GL_LINEAR_MIPMAP_LINEAR, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_NEAREST

07-23-2006, 12:57 PM
Hi, thanks!

I'll try this out.

By the way I do really need actual trilinear, how can I get to know which is it?... I cant find any paper about it.

thanks.

memfr0b
07-23-2006, 01:05 PM
GL_LINEAR_MIPMAP_LINEAR is what is called trilinear filtering.

GL_NEAREST_MIPMAP_NEAREST is nearest neighbor filtering using the best matching mipmap.

GL_LINEAR_MIPMAP_NEAREST is linear filtering on the best matching mipmap.

GL_NEAREST_MIPMAP_LINEAR is nearest neighbor filtering on the linear interpolation of the nearest two mipmaps.

des
07-24-2006, 03:14 AM
I thought that trilinier and anisotropy is the same. If it's right you should use extension

memfr0b
07-24-2006, 03:26 AM
Anisotropy is an additional functionality which reduces the blur introduced by trilinear filtering when looking at a surface at a steep angle. See Wikipedia - Anisotropic filtering (http://en.wikipedia.org/wiki/Anisotropic_filtering) for more information.