在没有PaintGL调用的情况下渲染到QOpenGLFramebufferObject

时间:2017-03-11 10:23:38

标签: qt opengl qtopengl

我想在不调用PaintGL的情况下调用渲染例程,原因是我正在尝试使用Qt OpenGL实现的现代例程来渲染多遍效果,因此伪代码应该是这样的:

for i=0 i<npasses i++
   glwidget->renderlayer i
glwidget->repaint //this calls PaintGL

问题在于,如果我从PaintGL函数中调用renderlayer,那么一切都会变得疯狂,它会在我的整个应用程序中被绘制而不是在我的glwidget(继承自QOpenGLWidget)上,另一方面,渲染层功能是可以的,因为只能从在PaintGL中,它的工作方式与预期的一样。

有关此的任何提示吗?

提前谢谢

1 个答案:

答案 0 :(得分:1)

您可以像这样创建QOffscreenSurface

QOpenGLWidget* widget = ...;
QOpenGLContext* ctx = widget->context();

QOffscreenSurface surface;
surface.setFormat(ctx->format());
surface.setScreen(ctx->screen());
surface.create();

然后将GL上下文重新定位到该屏幕外表面,进行FBO渲染,最后重新定位GL上下文。

ctx->makeCurrent(&surface);

// Bind FBO, do the rendering

widget->makeCurrent();
相关问题