title: How to update a texture using threads
body: <p>I am using ffmpeg to play video files and the project is not able to play multiple files in realtime so i would like to get into threads to update the textures.</p>
  <p>Though i have understanding of how to implement threading but i am clueless about what approach i should take in the current situation as i have many questions without answers.</p>
  <p>I have a class to update the texture.</p>
  <pre><code>class UpdateTexture
  {
  private:
      unsigned int textureID;
      std::string stdstrImagePath;
      unsigned char* data;
  
  public:
      void loadTexture(char const * path)
      {
          glGenTextures(1, &amp;textureID);  // generate the texture here
          // All other functions for texture creation like glTexImag2D            
      }
  
      void Update()
      {
          glBindTexture(GL_TEXTURE_2D, textureID);
          glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1920, 1080, GL_RGBA, GL_UNSIGNED_BYTE, data);
          glGenerateMipmap(GL_TEXTURE_2D);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
      }
  };
  </code></pre>
  <p>one object of this class will update one video file  so if i have 3 different video files playing i will have three objects of this class running in the back ground.</p>
  <p>This is the code for the main function.</p>
  <pre><code> UpdateTexture image;
   image.loadTexture(&quot;C:\\ShadersOld\\Images\\5rupeecoin.jpg&quot;);
   while (!glfwWindowShouldClose(window))
   {
      float time = glfwGetTime();     
      glClearColor(0.0, 0.0, 0.0, 0.0);
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
      processInput(window);
      shader.setMat4(&quot;view&quot;, view);
      shader.setMat4(&quot;projection&quot;, projection);
      shader.setMat4(&quot;model&quot;, model);
      glBindTexture(GL_TEXTURE_2D, 0);
      renderQuad();  // render the first rectangle without image
      
  
    // Draw the second rectangle
      glm::mat4 modelPosition = glm::mat4(1.0f);
      modelPosition = glm::translate(modelPosition, glm::vec3(-300.0f, 0.0f , 0.0f));
      shader.setMat4(&quot;model&quot;, modelPosition);
  //  image.Update(); // this process should run in the back ground and only update the texture of this rectangle 
      renderQuad();
      
  
      glfwSwapBuffers(window);
      glfwPollEvents();
  }
  </code></pre>
  <p>i would want to run the updateImage process in the background and only update the texture for the second rectangle not the first one.</p>
  <p>i can have a situation where there can be multiple video files playing so each updateTexture should be linked to its respective rectangle.</p>
  <p>I am very much confused in how can i link upDateTexture function to its respective rectangle and how would i shut down the upDateTexture threads once their respective rectangles have been destroyed ?</p>