title: Open GL texture flickering with GL_TEXTURE_MIN_FILTER at GL_NEAREST
body: <p>I have a simple OpenGL program built with GLUT that draws a few buildings, have a keyboard controlled moving camera, and I am trying to texture the ground.  The animation is smooth.</p>
  
  <p>The problem I have is with texturing mapping the ground.  Two separate issues with two separate approaches</p>
  
  <p>1) If I use glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); then I have no
  flickering when I zoom out to far away.  But the issue is when I zoom out from far, it appears as a single solid color.</p>
  
  <p>From far:</p>
  
  <p><img src="https://i.stack.imgur.com/KsTPy.png" alt="GL_LINEAREST_MIPMAP from far"></p>
  
  <p>From close:</p>
  
  <p><img src="https://i.stack.imgur.com/k8hfB.png" alt="GL_LINEAREST_MIPMAP from close"></p>
  
  <p>2) If I use, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); then I have a lot of flickering
  when I zoom out to far away as I move, almost look like a TV noise when you are out of tune.<br>
  But stationary, it looks more natural.</p>
  
  <p>From far:</p>
  
  <p><img src="https://i.stack.imgur.com/QGfCB.png" alt="GL_NEAREST from far"></p>
  
  <p>From close:</p>
  
  <p><img src="https://i.stack.imgur.com/TcArG.png" alt="GL_NEAREST from close"></p>
  
  <p><strong>Questions:</strong> What would be a simple way from my existing code to get the best of both worlds?  Looking natural from far, and no flickering of the texture as I move.  Thank you.</p>
  
  <p>Here is the relevant code:</p>
  
  <pre><code>GLuint  grassTextureId;
  GLfloat GROUND_PLANE_WIDTH = 1000.0f;
  
  void Display()
  {   
      glLoadIdentity();
      camera.Update();
      ...
      FlatGroundPlane_Draw(void);
      ...
  
      glutSwapBuffers();
  }
  
  void FlatGroundPlane_Draw(void) 
  {   
  
      glEnable(GL_TEXTURE_2D);            
      glBindTexture( GL_TEXTURE_2D, grassTextureId); // call glBindTexture before glBegin     
      glBegin(GL_QUADS);  
  
      glNormal3f(0, 1, 0);
      glTexCoord2d(0, 0); 
  
      GLdouble textCoord = GROUND_PLANE_WIDTH;
  
      glVertex3f( -GROUND_PLANE_WIDTH, 0, -GROUND_PLANE_WIDTH);
  
      // go beyond 1 for texture coordinate so it repeats and tiles
      glTexCoord2d(0, textCoord); 
      glVertex3f( -GROUND_PLANE_WIDTH, 0, GROUND_PLANE_WIDTH);
  
      glTexCoord2d(textCoord, textCoord); 
      glVertex3f( GROUND_PLANE_WIDTH, 0, GROUND_PLANE_WIDTH);
  
      glTexCoord2d(textCoord, 0); 
      glVertex3f( GROUND_PLANE_WIDTH, 0, -GROUND_PLANE_WIDTH);        
  
      glEnd();
  
      glDisable(GL_TEXTURE_2D);
  
  }
  
  void Initialise()
  {
  
      glEnable(GL_DEPTH_TEST);    
      glClearDepth(1.0f);    
      glDepthFunc(GL_LEQUAL); 
      glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);   
  
      modelParser = new ModelParser();
      // grass texture is 1024x1024
      // from http://seamless-pixels.blogspot.ca/2012_10_01_archive.html
      grassTextureId = modelParser-&gt;LoadTiledTextureFromFile("./Grass/Grass_1024.ppm");
  
  }
  
  void ModelParser::UploadTiledTexture(unsigned int &amp;iTexture, const RGBImage &amp;img)
  {
      glGenTextures(1, &amp;iTexture); // create the texture
      glBindTexture(GL_TEXTURE_2D, iTexture);
  
      // Issue 1: no flickering, but appear solid color from far away 
      //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
      //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  
  
      // Issue 2: flickering noise during movement but appear realistic from far away
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  
  
      // the texture would wrap over at the edges (repeat)
      glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
      glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
  
      gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img.Width(), img.Height(), GL_RGB, GL_UNSIGNED_BYTE, img.Data());
  }
  
  int main(int argc, char** argv)
  {
  
      ...
      glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
      ...
      glutDisplayFunc(&amp;GLUT::Display);
      ...
      glutMainLoop();
  }
  </code></pre>