Greg Dolley’s Weblog

A Blog about Graphics Programming, Game Programming, Tips and Tricks

OpenGL Texture Filter Parameters Explained

Posted by gregd1024 on January 17, 2008

As promised by a previous post entitled, “How to Turn Off Bilinear Filtering in OpenGL,” I’m going to explain the various texture filtering combinations behind these two very common OpenGL calls:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, <texture shrinkage filter>);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, <texture expansion filter>);

The value of parameter number three depends on whether you are setting a GL_TEXTURE_MIN_FILTER variable or a GL_TEXTURE_MAG_FILTER variable. Here are the possible combinations:

  1. When the second parameter is GL_TEXTURE_MIN_FILTER, parameter three can be:
    1. GL_NEAREST_MIPMAP_NEAREST
    2. GL_LINEAR_MIPMAP_NEAREST
    3. GL_NEAREST_MIPMAP_LINEAR
    4. GL_LINEAR_MIPMAP_LINEAR
    5. GL_NEAREST
    6. GL_LINEAR
  2. When the second parameter is GL_TEXTURE_MAG_FILTER, parameter three can be:
    1. GL_LINEAR
    2. GL_NEAREST

The filter value set for GL_TEXTURE_MIN_FILTER is used whenever a surface is rendered with smaller dimensions than its corresponding texture bitmap (far away objects). Whereas the filter value for GL_TEXTURE_MAG_FILTER is used in the exact opposite case – a surface is bigger than the texture being applied (near objects).

There are more options for the min filter because it can potentially have mipmapping. However, it wouldn’t make sense to apply mipmapping to the mag filter since close-up objects don’t need it in the first place. Here’s a list of all the possible combinations and how they impact what is rendered (first constant in the left-most column is the near object filter [mag]; second constant is the far object filter [min]):

Filter Combination (MAG_FILTER/MIN_FILTER) Bilinear Filtering (Near) Bilinear Filtering (Far) Mipmapping
GL_NEAREST / GL_NEAREST_MIPMAP_NEAREST Off Off Standard
GL_NEAREST / GL_LINEAR_MIPMAP_NEAREST Off On Standard
GL_NEAREST / GL_NEAREST_MIPMAP_LINEAR Off Off Use trilinear filtering
GL_NEAREST / GL_LINEAR_MIPMAP_LINEAR Off On Use trilinear filtering
GL_NEAREST / GL_NEAREST Off Off None
GL_NEAREST / GL_LINEAR Off On None
GL_LINEAR / GL_NEAREST_MIPMAP_NEAREST On Off Standard
GL_LINEAR / GL_LINEAR_MIPMAP_NEAREST On On Standard
GL_LINEAR / GL_NEAREST_MIPMAP_LINEAR On Off Use trilinear filtering
GL_LINEAR / GL_LINEAR_MIPMAP_LINEAR On On Use trilinear filtering
GL_LINEAR / GL_NEAREST On Off None
GL_LINEAR / GL_LINEAR On On None

 

Not all of these combinations make sense to use. For example, there’s no point in applying GL_NEAREST with GL_LINEAR_MIPMAP_LINEAR because you’ll still see a sharp “break” between the trilinear filtered portion of a surface and the non-filtered portion. You should use whichever combination makes sense visually without compromising performance.

-Greg Dolley

*Get new posts automatically! Subscribe via RSS here . Want email updates instead? Click here.

6 Responses to “OpenGL Texture Filter Parameters Explained”

  1. Ivan said

    What would be the correspondent function call for DirectX to turn off filtering when magnifying?

  2. gregd1024 said

    Sorry, Ivan, I haven’t tried to do it in DirectX, so I’m not sure.

    -Greg

  3. Andy said

    Thanks a lot for this excellent summary. One annotation:
    Not all of these combinations make sense to use. For example, there’s no point in applying GL_NEAREST with GL_LINEAR_MIPMAP_LINEAR because you’ll still see a sharp “break” between the trilinear filtered portion of a surface and the non-filtered portion.
    This might be true for games. As i write a visualizer for filtered images, diplaying results in textures, i am actually interested in real, not good results. So i choose GL_NEAREST as MAG Filter. In cae is have to display the results in smaller scale, i still want them to show noise and use GL_LINEAR_MIPMAP_LINEAR for best results. So, when not making games, all the combinations might be usefull :o)

  4. […] OpenGL Filter Parameters Explained by Greg Dolley […]

  5. […] OpenGL Filter Parameters Explained by Greg Dolley […]

Leave a comment