title: I'm trying to update a texture with glTexSubImage2D
body: <p>I started learning OpenGL recently and I've been messing with texture. I updated my texture using <code>glTexImage2D</code> but I've learned that it's better to use <code>glTexSubImage2D</code>, so I tried to change my code but i doesn't work. </p>
  
  <p><strong>Working code</strong> </p>
  
  <pre><code>void GLWidget::updateTextures(){
  
      QImage t = img.mirrored();
  
      glBindTexture(GL_TEXTURE_2D, tex);
  
          glTexImage2D(GL_TEXTURE_2D, 0, 3, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits());
  
      glBindTexture( GL_TEXTURE_2D, 0);
  }
  </code></pre>
  
  <p><strong>Not working code</strong></p>
  
  <pre><code>void GLWidget::updateTextures(){
  
      QImage t = img.mirrored();
  
      glBindTexture(GL_TEXTURE_2D, tex);
  
          glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, t.width(), t.height(), GL_RGBA, GL_UNSIGNED_BYTE, t.bits());
  
      glBindTexture( GL_TEXTURE_2D, 0);
  }
  </code></pre>
  
  <p>All I have is a black screen. </p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT :</strong> </p>
  
  <p>Here is the initialization of my texture : </p>
  
  <pre><code>void GLWidget::initializeGL(){
  
  ...
  
      LoadGLTextures();
  
  ...
  
  }
  
  void GLWidget::LoadGLTextures(){
  
  
      QImage t = img.mirrored();
  
      glGenTextures(1, &amp;tex);
  
      glBindTexture(GL_TEXTURE_2D, tex);
  
          glTexImage2D(GL_TEXTURE_2D, 0, 3, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits());
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  
      glBindTexture( GL_TEXTURE_2D, 0);
  
  }
  </code></pre>
  
  <p><code>img</code> is a <code>QImage</code> variable containing the pixel data. </p>
  
  <p><code>glGetError()</code> Returns code 1281.</p>