Linux下使用wxGLCanvas導致畫面閃爍的解決方案

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平臺下使用wxWidget s作OpenGL應用開發時,需要使用wxGLCanvas 作爲OpenGL畫面的載體. 如果使用默認參數來初始化wxGLCanvas,那麼在每一次重繪事件後,畫面就會閃爍一下(Windows平臺下不會出現這樣的閃爍)。尤其是繪製的東西很複雜時,閃爍會非常明顯。

    wxWidgets的文檔說會自動以雙緩衝的模式來初始化wxGLCanvas,但是據我目前所知,這是一個bug。事實上,我們必須手動的設置雙緩衝,來避免畫面閃爍。

    手動設置的關鍵參數就是 ' int* attribList = 0 '(關於wxGLCanvas初始化參數,請參考這裏 )。這個參數默認爲0,我們通過以下的初始化方法來打開OpenGL雙緩衝:

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

    通過這樣的初始化,打開OpenGL的雙緩衝,重繪時的閃爍便能夠消除。

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章