views:

204

answers:

3

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?

Edit:

Here's the question I'm really after:

How do you programmactically check if mip-mapping is available on a platform?

+3  A: 

OpenGL 1.4 is required for support for automatic mipmap generation (using GL_GENERATE_MIPMAP), texturing using mipmaps should be available on virtually every graphic card out there. I guess the problem might not be missing mipmapping functionality but maybe the generation of the mipmaps. Just for debugging purposes, can you try generating the mipmaps using gluBuild2DMipmaps?

If this problem is specific to this graphic card/configuration, checking for updated drivers might be a good idea, too.

A good method to get rid of aliasing is multisampling.

Greg S
`gluBuild2DMipmaps()` - yes, I can try that. However it is not my machine, so you won't hear back a result for perhaps months. But I will keep it in mind, thanks!
Xavier Ho
Multisampling does nothing to avoid texture aliasing inside triangles. It only affects polygon boundaries.
Bahbar
@Bahbar, perhaps @Greg meant supersampling, which is a fine solution but too slow for my needs.
Xavier Ho
For what it's worth, OpenGL 3.2 added support for texture multisampling (http://www.opengl.org/registry/specs/ARB/texture_multisample.txt), although I freely admit that I mixed things up ;-)
Greg S
That's about rendering to a multisample buffer based on a texture, not about multisampling textured primitives.
Malte Clasen
@Greg, @Malte, I've added a question in bold in my original question to hopefully clarify my intention. Any hints?
Xavier Ho
+2  A: 

If no mip-mapping is available, your probably don't want to avoid the aliasing. A platform without mip-mapping is usually not worth the trouble.

However, if you really really want to avoid aliasing, you could approximate per-fragment mip-mapping by per-primitive mip-mapping. First you have to generate and upload all mip-map-levels by hand into separate textures. Before rendering a triangle, compute the appropriate mip-map level on the cpu and use the texture corresponding to this mip-map level. To avoid artifacts on large primitives, subdivide them.

Malte Clasen
Thanks for the tips. Sounds like there's always a last resort. :]
Xavier Ho
+2  A: 

OpenGL requires that all texture formats that are part of the Core support mip-mapping. As such there is no specific way to ask whether a texture format supports mip-mapping.

Some extensions, when first introduced, were relaxing this constraint for new formats (most notably, non-power of two textures, and float textures). The extension itself made it clear that the mip-mapping was not supported at all. But before those got integrated into the core, the requirement for mip-mapping support was reinstated.

Bahbar
@Bahbar: Ack, thanks. I hoped it didn't come down to that. Oh well.
Xavier Ho