Code Snippets
What's That?
I am using it actively
I planning to use/learn it
I don't plan to lean/use it
5th option
Home :: Programming :: Code Snippets :: OpenGL :: Anisotropic Filtering

[ Anisotropic Filtering ]

When using mipmapped textures in your OpenGL applications you might sometimes notice that those textures are often severly blurred when the camera looks at the them from an oblique angle. That's because the texture mapping mode assumes that the texture space is a square - so isotropic - while in reality it's rather long and narrow - anisotropic. And here's where anisotropic filtering comes into the game which allows to increase texture quality of those textures.

So as we are dealing with an extension, it would be better to first check whether this extension is really supported by our graphics driver:

//check whether extension string can be found
if (!strstr((char*)glGetString(GL_EXTENSIONS), 
   // do whatever you want but don't
   // use anisotropic filtering ;-)

Then we need two defines used by this extension. Either you include glext.h - link can be found in the code section - or you create the defines yourself:


If we are sure that anistropic filtering is supported, we are free to create our textures using this extension. Like setting what MIN_FILTER should be used for this texture, you also do the same here. The corresponding texture attribute is GL_TEXTURE_MAX_ANISOTROPY_EXT:

// texture creation code
// ...


glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy);
As you see, the maximum anisotropy is a float and it has to be greater than 1.0 when the extension should take effect. The maximum value that is supported by your graphics cards can be retrieved with glGetFloatv(..):

float maximumAnistropy;

//get the value
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy);

That's it! This extension really belongs to the most easiest ones to use. If you like you can compare filtered and non-filtered textures in the anistropic filtering test app I wrote. At the same time you might see that the effects aren't that overwhelming. Questions? Message Board! Happy Coding!

 Last edited 2003-12-18 21:48:35 by André Stein - printable version
» copyright by andré stein
» using stCM v1.0
» steinsoft.net revision 5.0