【问题标题】:Render loop function in QT to render opengl in WindowsQT中的渲染循环函数在Windows中渲染opengl
【发布时间】:2014-01-15 09:29:20
【问题描述】:

由于 QGLWidget 不能用于 OpenGL / ES,所以我在 Qt 中留下了 QWidget 用于小部件渲染 opengl。 Reference

如果我有以下 renderView 函数要在当前窗口中呈现,我正在寻找将由 qt 重复调用的“那个”函数,以便 QWidget 刷新屏幕,以便我可以通过重载它来调用该函数中的 renderView。

知道如何做到这一点或常见的解决方法吗?

原始问题:我不想根据屏幕刷新率在 1 毫秒甚至 16.66 毫秒的计时器内调用 renderView。

class MyWindow
{
    void renderView()
    {   
        if(DeviceContext && RenderingContext)
        {
            wglMakeCurrent(m_hdc, m_hrc); //Set current context

            glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
            glClear(GL_COLOR_BUFFER_BIT);       
            // glViewPort.... and render using shaders

            SwapBuffers(m_hdc); // Double buffering thats why
        }   
    }
};

class MyWidget : public QWidget, public MyWindow
{
     // What is the function called repeatedly to refresh the screen
     // so that i would ask that function to call renderView
};

提前致谢!

【问题讨论】:

    标签: c++ qt opengl-es render qwidget


    【解决方案1】:

    由于 QGLWidget 不能用于 OpenGL / ES

    是的,我们需要澄清一些困惑,然后再继续往下走……

    可以。发明这个小部件是为了扩展通常的QWidget 界面,支持 OpenGL 桌面和嵌入式支持。请参考以下示例,了解是否可以将此小部件用于 OpenGL ES 功能:

    OpenGL Hello GL ES Example

    现在,我们可以开始回答您的问题了。您可能应该重新实现以下受保护的方法。

    void QGLWidget::paintGL() [virtual protected]

    每当需要绘制小部件时都会调用此虚拟函数。在子类中重新实现它。

    在我们讨论它的同时,请检查受保护的初始化方法:

    void QGLWidget::initializeGL() [virtual protected]

    此虚函数在第一次调用paintGL() 或resizeGL() 之前调用一次,然后在为小部件分配新的QGLContext 时调用一次。在子类中重新实现它。

    这个函数应该设置任何需要的 OpenGL 上下文渲染标志,定义显示列表等。

    实际上,您甚至可以按照以下受保护的方法使用此接口处理叠加层:

    void QGLWidget::paintOverlayGL() [virtual protected]

    这个虚函数的使用方式与paintGL() 相同,只是它作用于小部件的覆盖上下文而不是小部件的主上下文。这意味着只要需要绘制小部件的叠加层,就会调用paintOverlayGL()。在子类中重新实现它。

    void QGLWidget::initializeOverlayGL() [virtual protected]

    这个虚函数的使用方式与 initializeGL() 相同,只是它在小部件的覆盖上下文而不是小部件的主上下文上运行。这意味着在第一次调用paintOverlayGL() 或resizeOverlayGL() 之前调用了一次initializeOverlayGL()。在子类中重新实现它。

    此函数应该为覆盖上下文设置任何必需的 OpenGL 上下文渲染标志、定义显示列表等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-17
      • 2019-04-02
      • 2016-03-14
      • 2018-10-02
      • 2013-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多