title: Loading image to opengl texture qt c++
body: <p>I'm using opengl calls on Qt with c++, in order to display images to the screen. In order to get the image to the texture, I first read it as a QImage, and then use the following code to load to texture:</p>
  
  <pre><code>void imageDisplay::loadImage(const QImage &amp;img){
      glEnable(GL_TEXTURE_2D); // Enable texturing
      glBindTexture(GL_TEXTURE_2D, texture); // Set as the current texture
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
      glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, img.width(),
                    img.height(),
                    0, GL_BGRA,      GL_UNSIGNED_BYTE, img.bits() );
      glFinish();
      glDisable(GL_TEXTURE_2D);
  }
  </code></pre>
  
  <p>However, when profiling performance, I suspect this is not the most efficient way of doing this. Performance is critical for the application that I am developing, and I would really appreciate any suggestions on how to improve this part. 
  (BTW - reading the image is done on a separate module than the one that is displaying it - is it possible to read and load to a texture, and then move the texture the displaying object?)</p>
  
  <p>Thank you</p>