X11窗口调整口吃大小

时间:2016-04-04 23:40:19

标签: linux opengl x11

我正在X11中创建一个openGL窗口并使用glxswapbuffers进行双缓冲。

问题是:渲染看起来很好但是我在调​​整大小时会让openGL内容反弹并且窗口边框会出现断断续续的情况。

我尝试过滤ConfigureNotify事件,延迟它们,使用glXSwapInterval设置vsync关闭......没有任何效果。

这是我正在使用的代码

void Window::redraw() { // Called by any control which needs redrawing
  XEvent event;
  memset(&event, 0, sizeof(event));
  event.type = Expose;
  event.xexpose.display = display;
  XSendEvent(display, window, False, ExposureMask, &event);
}

void Window::resize(int width, int height) {
  this->Width = width;
  this->Height = height;
}

bool Window::wndProc(XEvent *evt) {
  switch (evt->type) {

      case Expose: {

        if (evt->xexpose.count == 0) { // handle last one only

          while (XCheckTypedWindowEvent(display, window, Expose, evt));

            if (Width != oldWidth || Height != oldHeight)
              resizeViewportAndUpdateDimensions();

          Renderer.drawGLStuff();

          this->redraw();
        }

        return true;

      } break;

      case ConfigureNotify: {
        this->resize(evt->xconfigure.width, evt->xconfigure.height);

        this->redraw();
        return true;
      } break;
  }
}

请注意,这是一个与我通过XCheckTypedWindowEvent解决的this previous post不同的问题(与调整大小相关)。

1 个答案:

答案 0 :(得分:0)

https://tronche.com/gui/x/xlib/events/window-state-change/configure.html

https://tronche.com/gui/x/xlib/events/structure-control/resize.html

从我可以从这两个链接中读取的内容,当更改完成时,会发生ConfigureNotify。尝试调整大小时发生ResizeRequest。具体做法是:

  

X服务器可以向想要的客户报告ResizeRequest事件   有关另一个客户尝试更改a的大小的信息   窗口。

我不喜欢“CAN报告”的声音,但我想你应该试一试。不要忘记按照链接中的说明设置正确的事件位。至于捕获事件时你应该​​做些什么我不太确定......我会清除前缓冲区并等待调整大小来完成。