title: How can I prevent binding random texture in OpenGL Qt?
body: <p>I store my textures IDs in <code>GLuint textures[]</code> array. When I try to bind first of them (textres[0]) i get random one instead. Sometimes good, but mostly not. Every other works just fine. I also tried binding this texture in other drawing methods and it behaved the same way. My loading function:</p>
  
  <pre><code>int Screen::loadTextures()
  {
      Images.clear();
  
      Images.append(QImage("APPLE.png"));
      Images.append(QImage("V.png"));
      Images.append(QImage("TAIL.png"));
      Images.append(QImage("DTOR.png"));
      Images.append(QImage("HEAD.png"));
      Images.append(QImage("BACK.png"));
      Images.append((QImage("PLUS10.png")));
      Images.append((QImage("SPEEDUP.png")));
  
      for(int i = 0; i&lt;Images.size(); ++i)
      {
          Images[i] = QGLWidget::convertToGLFormat(Images[i]);
          if(Images[i].isNull()) return 0;
      }
  
      textures = new GLuint[Images.size()];
      glGenTextures(Images.size(), &amp;textures[Images.size()]);
  
      for(int i=0; i&lt;Images.size(); ++i)
      {
          glBindTexture(GL_TEXTURE_2D,textures[i]);
          glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
          glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
          glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Images[i].width(), Images[i].height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, Images[i].bits());
      }
  
      return 1;
  }
  </code></pre>
  
  <p>and painting:</p>
  
  <pre><code>void Screen::drawApple(int X, int Y)
  {
      #define JEDNOSTKA = 0.2
      glPushMatrix();
  
      glBindTexture(GL_TEXTURE_2D,textures[0]);
  
      glTranslated(X*JEDNOSTKA, Y*JEDNOSTKA,0);
      glBegin(GL_POLYGON);
  
      glTexCoord2f(0,1);
      glVertex3d(-JEDNOSTKA/2, JEDNOSTKA/2,0);
      glTexCoord2f(1,1);
      glVertex3d( JEDNOSTKA/2, JEDNOSTKA/2,0);
      glTexCoord2f(1,0);
      glVertex3d( JEDNOSTKA/2,-JEDNOSTKA/2,0);
      glTexCoord2f(0,0);
      glVertex3d(-JEDNOSTKA/2,-JEDNOSTKA/2,0);
  
      glEnd();
      glPopMatrix();
  
  }
  </code></pre>