代码之家  ›  专栏  ›  技术社区  ›  Geoff

在OpenGL中动态更改纹理

  •  5
  • Geoff  · 技术社区  · 14 年前

    texture 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);
    }
    

    我初始化第一个图像 glutMainLoop() 显示正确。它被赋予了身份 1

    编辑: 另一个线索,我有子窗口。如果我在另一个窗口中进行注释,代码将按预期工作。

    2 回复  |  直到 14 年前
        1
  •  2
  •   Thomas    14 年前

        2
  •  1
  •   Martin Beckett    14 年前

    您是否正在尝试按顺序显示新图像而不是现有图像?
    在这种情况下,您只需要更改image.data,而不需要创建新的纹理绑定。