我遇到了使用QOpenGLFramebufferObject
.
但是,如果我将默认帧缓冲区复制到QOpenGLFramebufferObject
using中,它会起作用glBlitFramebuffer
。我不知道原因。
这是代码:
void SceneView3D::paintGL()
{
QOpenGLContext *ctx = QOpenGLContext::currentContext();
QOpenGLFramebufferObjectFormat fboFormat;
fboFormat.setSamples(0);
fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
m_framebuffer = new QOpenGLFramebufferObject(this->width(), this->height(), fboFormat);
m_framebuffer->bind();
// --------------------------------------
// draw scene here
//-------------------------------------
QImage image = m_framebuffer->toImage();
image.save(R"(image.jpg)");
m_framebuffer->release();
}
我创建了QOpenGLFramebufferObject
并且已经设置了深度附件,但在输出图像中没有绘制任何内容。似乎颜色附件丢失了。
但是如果我在绘图之前添加这些代码,它就起作用了。
glBindFramebuffer(GL_READ_FRAMEBUFFER, defaultFramebufferObject());
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_framebuffer->handle());
ctx->extraFunctions()->glBlitFramebuffer(0, 0, width(), height(), 0, 0, m_framebuffer->width(), m_framebuffer->height(), GL_DEPTH_BUFFER_BIT, GL_NEAREST);
所以,我不知道为什么 defaultFramebufferObject 中的深度信息而不是我创建的 m_framebuffer 中的深度信息。
有什么想法可以解决吗?