How to check for mip-map availability in OpenGL?

Posted by Xavier Ho on Stack Overflow See other posts from Stack Overflow or by Xavier Ho
Published on 2010-06-18T08:00:07Z Indexed on 2010/06/18 8:03 UTC
Read the original article Hit count: 251

Recently I bumped into a problem where my OpenGL program would not render textures correctly on a 2-year-old Lenovo laptop with an nVidia Quadro 140 card. It runs OpenGL 2.1.2, and GLSL 1.20, but when I turned on mip-mapping, the whole screen is black, with no warnings or errors.

This is my texture filter code:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

After 40 minutes of fiddling around, I found out mip-mapping was the problem. Turning it off fixed it:

// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

I get a lot of aliasing, but at least the program is visible and runs fine.

Finally, two questions:

  1. What's the best or standard way to check if mip-mapping is available on a machine, aside from checking OpenGL versions?
  2. If mip-mapping is not available, what's the best work-around to avoid aliasing?

© Stack Overflow or respective owner

Related posts about best-practices

Related posts about opengl