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

9 篇文章 0 订阅
6 篇文章 0 订阅

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的双缓冲,重绘时的闪烁便能够消除。

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值