glutpostredisplay() 相当于 winapi

glutpostredisplay() equivalent in winapi

我正在关注 this 文章,使用 C++ 使用 OpenGL 和 winforms 将视频渲染到纹理上。 我更改了渲染器中的代码如下。但是 glutPostRedisplay();不管用。当我创建 OpenGL window 并在那里渲染时,相同的逻辑工作得很好。但在 winform 中似乎效果不佳。 据我了解,glutPostRedisplay 正在尝试刷新我的主要 winforms window 而不是 OpenGL 视口。我不确定如何刷新我的视口。

 void OpenGLForm::COpenGL::Render(System::Void)
{   
  //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glEnable(GL_TEXTURE_2D);
  // These are necessary if using glTexImage2D instead of gluBuild2DMipmaps
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);


  // Draw a textured quad
  glBegin(GL_QUADS);
  glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
  glTexCoord2f(1.0f, 0.0f); glVertex2f(frame_width, 0.0f);
  glTexCoord2f(1.0f, 1.0f); glVertex2f(frame_width, frame_height);
  glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, frame_height);
  glEnd();

   glFlush();
 //glutSwapBuffers();

 OpenGLForm::COpenGL::SwapOpenGLBuffers();

//Get data from the camera
 uint32_t* buffer = new uint32_t[frame_width * frame_height * 4];
 if (display_mode == DISPLAY_ARGB) {
     // Pass a pointer to the texture directly into Thermal_GetImage for maximum performance
     status = Thermal_GetDisplayImage(camera, buffer, (uint32_t)frame_pixels);


   glTexImage2D(
       GL_TEXTURE_2D,
       0,
       GL_RGBA8,
       frame_width,
       frame_height,
       0,
       GL_RGBA,
       GL_UNSIGNED_BYTE,
       buffer);


    // Clean up buffer
    delete[] buffer;

   // Update display
   glutPostRedisplay();
}

void OpenGLForm::COpenGL::SwapOpenGLBuffers(System::Void)
{
   SwapBuffers(m_hDC);
}

glutPostRedisplay 仅适用于“过剩”-window。 (glutCreateWindow). You have to use a Win-API function to invalidate the client area of the window (e.g. InvalidateRect):

InvalidateRect(HWND, NULL, TRUE);