Linux下使用wxGLCanvas导致画面闪烁的解决方案

来源:互联网 发布:linux文件修改权限 编辑:程序博客网 时间:2024/04/29 16:06

Solution to The Flicker When Using wxGLCanvas on Linux Platform

 

    When we develop OpenGL applications under Linux with wxWidgets, we need wxGLCanvas as the OpenGL container. If we initialize the wxGLCanvas with default parameters, the whole drawing area will flicker after every redrawing(In Windows Platforms, this problem will not appear). This will be obvious when the drawing stuff is very complex especially.

    wxWidgets docs told us that wxGLCanvas will use OpenGL double buffer by default. But this is a bug as far as I know. In fact, the default parameter will not initialize OpenGL double buffer, we must do this manually to avoid flicker.

    The key point is the parameter ' int* attribList = 0' (You can refer to here). This parameter will be set to 0 by default. We should do like this if we wanna use OpenGL double buffer:

    Here GL_Window is my class name.

 

    After doing this, the flicker will disappear when re-draw event happened.

 

 

 

Linux下使用wxGLCanvas导致画面闪烁的解决方案


    在Linux平台下使用wxWidgets作OpenGL应用开发时,需要使用wxGLCanvas作为OpenGL画面的载体. 如果使用默认参数来初始化wxGLCanvas,那么在每一次重绘事件后,画面就会闪烁一下(Windows平台下不会出现这样的闪烁)。尤其是绘制的东西很复杂时,闪烁会非常明显。

    wxWidgets的文档说会自动以双缓冲的模式来初始化wxGLCanvas,但是据我目前所知,这是一个bug。事实上,我们必须手动的设置双缓冲,来避免画面闪烁。

    手动设置的关键参数就是 ' int* attribList = 0'(关于wxGLCanvas初始化参数,请参考这里)。这个参数默认为0,我们通过以下的初始化方法来打开OpenGL双缓冲:

    其中GL_Window是我自己Canvas的类名。

    通过这样的初始化,打开OpenGL的双缓冲,重绘时的闪烁便能够消除。