Search code examples
opengltexturesjoglantialiasingmipmaps

JOGL mipmaps and texture shimmering


I've a wall and a brick texture in my OpenGL 2 scene that keeps shimmering and flashing no matter what I set. When I'm zoomed in close (and can see clearly the texture), then the flashing and shimmering stops. But when I'm zoomed out and moving around the scene, the flashing and shimmering is very pronounced. This is the texture code for the brick wall:

brickwall.setTexParameteri(gl, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
brickwall.setTexParameteri(gl, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
brickwall.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER,GL2.GL_NEAREST);
brickwall.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER,GL2.GL_LINEAR);
gl.glGenerateMipmap(GL2.GL_TEXTURE_2D);

brickwall.enable(gl);
brickwall.bind(gl);
//...
brickwall.disable(gl);

From what I've googled, it seems that this is a problem that mipmapping solves. But my question is, how does one do this? Do I have to create, load and set parameters for all the various power of 2 sized images? Can anyone give me an example for loading and displaying a JOGL2 texture using mipmaps that won't flicker and shimmer zooming and moving about a scene?


Solution

  • You are generating the mipmap chain with glGenerateMipmap, but you didn't set an appropiate MIN filter:

    brickwall.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER,GL2.GL_LINEAR_MIPMAP_LINEAR);
    

    The *MIPMAP* filters use mipmaps, the other texture filters don't.