PDA

View Full Version : Anisotropic filtering does not work?



game a gogo
06-09-2012, 07:28 AM
Before I start explaining my problem in detail, please bear in mind I've only started programming in OpenGL for a few months at my college, I'm using SOIL, GLEW and OpenGL 3.3 as my tools at the moment.

I've started making a 3D scene for a project at my college and everything is going well so far, except for one thing: My instructor and I can't seem to be able to enable Anisotropic filtering?
We've spent a day or two searching about how we could get Anisotropic filtering to work, on all documentations I've found, this is quite the simple thing to enable!

I have this code that should enable anisotropic filtering:

GLfloat largest_supported_anisotropy;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &largest_supported_anisotropy);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, largest_supported_anisotropy);

I also have mipmapping enabled in both OpenGL and SOIL, so anisotropy shouldn't have any problem being enabled, right?

Not quite, for some reason this code does not do the trick, after spending hours on searching about this, there doesn't seem to be any alternatives.

As a proof that anisotropy never gets set, I can force it to 16x in my video card control panel, compare for yourself:
755
This picture is without forcing anisotropy to 16x, but yet still having the code that should enable it, clearly it's not enabled when you compared it with the following image:
756
(It's hard to notice since the pictures are resized, but the first one has blue spots in the near distance while the other one with anisotropy forced, those blue spots disappears and the texture is much clearer)

I've tried adding a breakpoint just after the glGetFloatv, and largest_supported_anisotropy is equal to 16.f, which corresponds with what my video card can do.

This happens for both NVidia and ATI graphic cards, as I've had my friend try this with the same results.

I'm sorry if this question may seem stupid, but I can't seem to find the answer anywhere to my problem. Any help is greatly appreciated!
If you need more information, I'll be more than happy to provide!
Again, thanks in advance!

Alfonse Reinheart
06-09-2012, 07:42 AM
I have this code that should enable anisotropic filtering:

As the code suggests, anisotropic filtering is a per-texture parameter, not global state. You don't "enable anisotropic filtering". You tell a specific texture to use anisotropic filtering.

The code you've posted here will only work if the texture you want to use aniso with is currently bound. And then, it will only work for that texture. Just as you must enable mipmap filtering on specific textures, so too must you use anisotropic filtering on specific textures.

game a gogo
06-09-2012, 07:55 AM
Thank you so much! I've included the code within the texture loading method, now it works!

This is actually the first mention of anisotropy being texture-specific... perhaps I wasn't looking in the right place!

Again, thank you, and I'm sure my instructor will be thankful as well :)

V-man
06-09-2012, 02:01 PM
glTexParameter calls are for setting up the texture object.

If anisotropy was a global state, it would be glEnable(GL_TEXTURE_ANISOTROPY_EXT);

BTW, http://www.opengl.org/wiki/Common_Mistakes#glGetError

mhagain
06-09-2012, 09:11 PM
It doesn't need to be mentioned that anisotropic filtering is texture-specific - as soon as you see a glTexParameter call you know that you're dealing with something that's texture-specific. That's also going to apply to anything such as LOD, mipmap generation, and anything else that uses glTexParameter calls.