C++ cairo+错误;自由结合

C++ cairo+错误;自由结合,c++,opengl,glut,cairo,freeglut,C++,Opengl,Glut,Cairo,Freeglut,我用freeglut创建一个GL上下文,如下所示: glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_STENCIL); if (!device_) { device_ = cairo_glx_device_create(glXGetCurrentDisplay(), glXGetCurrentContext()); } // else do nothing auto const surface(ca

我用
freeglut
创建一个
GL
上下文,如下所示:

glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_STENCIL);
  if (!device_)
  {
    device_ = cairo_glx_device_create(glXGetCurrentDisplay(),
      glXGetCurrentContext());
  }
  // else do nothing

  auto const surface(cairo_gl_surface_create_for_window(device_,
    glXGetCurrentDrawable(), width, height));

  auto const cr(cairo_create(surface));

  // draw using cairo calls

  cairo_destroy(cr);
  cairo_gl_surface_swapbuffers(surface); // !!!
  cairo_surface_destroy(surface);
还有一张画有
cairo
的画,像这样:

glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_STENCIL);
  if (!device_)
  {
    device_ = cairo_glx_device_create(glXGetCurrentDisplay(),
      glXGetCurrentContext());
  }
  // else do nothing

  auto const surface(cairo_gl_surface_create_for_window(device_,
    glXGetCurrentDrawable(), width, height));

  auto const cr(cairo_create(surface));

  // draw using cairo calls

  cairo_destroy(cr);
  cairo_gl_surface_swapbuffers(surface); // !!!
  cairo_surface_destroy(surface);
如果我不调用
cairo\u gl\u surface\u swapbuffers()
,而是调用
glutSwapBuffers()
,则不会显示任何内容,但会出现错误:

X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  156 (GLX)
  Minor opcode of failed request:  11 (X_GLXSwapBuffers)
  Serial number of failed request:  69
  Current serial number in output stream:  72

但是,如果我调用
cairo\u gl\u surface\u swapbuffers()
,但不调用
glutSwapBuffers()
,图形将显示,并且不会出现错误。如何调用
glutSwapBuffers()
,而不是
cairo\u gl\u surface\u swapbuffers()
,而不触发错误?我想将其他内容与
cairo
内容混合使用。

函数
cairo\u gl\u surface\u swapbuffers
应该相当于调用
cairo\u surface\u flush
然后调用正确的函数来交换缓冲区


所以我猜您正在寻找
cairo\u surface\u flush(surface)

如果cairo按照这个建议包装GLX,那么您应该完成它。如果允许cairo管理调用线程的活动GLX上下文之类的内容,FreeGLUT将做出可能不成立的假设。当然,但我使用
cairo
GLX
上下文初始化它,我不知道是否正在创建一个新的。也许有人玩过类似的东西。不行,还是会出现错误。如果你有一个有效的例子,请发布它。