【发布时间】:2019-08-30 13:50:25
【问题描述】:
当我使用QOpenGLFramebufferObject 时,我遇到了深度测试不起作用的问题。
但如果我使用glBlitFramebuffer 将默认帧缓冲区复制到QOpenGLFramebufferObject,它会起作用。不知道是什么原因。
代码如下:
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 中的深度信息。
有什么想法可以解决吗?
【问题讨论】:
标签: c++ qt opengl depth-testing