gpt4 book ai didi

c++ - QT中的渲染循环函数在Windows中渲染opengl

转载 作者:太空宇宙 更新时间:2023-11-04 11:42:35 28 4
gpt4 key购买 nike

由于 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
};

提前致谢!

最佳答案

Since QGLWidget cannot be used for OpenGL / ES

是的,我们需要先理清一些困惑,然后再继续下去......

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

OpenGL Hello GL ES Example

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

void QGLWidget::paintGL() [virtual protected]

This virtual function is called whenever the widget needs to be painted. Reimplement it in a subclass.

在我们讨论的同时,还请检查 protected 初始化方法:

void QGLWidget::initializeGL() [virtual protected]

This virtual function is called once before the first call to paintGL() or resizeGL(), and then once whenever the widget has been assigned a new QGLContext. Reimplement it in a subclass.

This function should set up any required OpenGL context rendering flags, defining display lists, etc.

事实上,您甚至可以按照以下 protected 方法使用此接口(interface)处理叠加层:

void QGLWidget::paintOverlayGL() [virtual protected]

This virtual function is used in the same manner as paintGL() except that it operates on the widget's overlay context instead of the widget's main context. This means that paintOverlayGL() is called whenever the widget's overlay needs to be painted. Reimplement it in a subclass.

void QGLWidget::initializeOverlayGL() [virtual protected]

This virtual function is used in the same manner as initializeGL() except that it operates on the widget's overlay context instead of the widget's main context. This means that initializeOverlayGL() is called once before the first call to paintOverlayGL() or resizeOverlayGL(). Reimplement it in a subclass.

This function should set up any required OpenGL context rendering flags, defining display lists, etc. for the overlay context.

关于c++ - QT中的渲染循环函数在Windows中渲染opengl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20806618/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com