Dynamic texture change in OpenGL

I have code (OpenCV) that generates images. I show them using OpenGL. When new images are created, I run the following function (each time) with the same name textureand new image:

void loadCVTexture(GLuint& texture, const cv::Mat_<Vec3f>& image){
  if(texture != 0){
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image.cols, image.rows, GL_BGR, GL_FLOAT, image.data);
  } else {
    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, image.cols, image.rows, 0, GL_BGR, GL_FLOAT, image.data);
  }
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}

I initialize the first image to glutMainLoop()and it will display correctly. It is assigned id 1. When I refresh the image again, the image does not change. (I confirmed that the display function is being called and that the image is different.)

Edit: Another key, I have sub-windows. If I comment on another window, the code works as expected.

+5
source share
2 answers

"-", , OpenGL .

, .

+2

?
image.data, .

+1

All Articles