1

我尝试按照将深度渲染缓冲区复制到深度缓冲区进行操作,但它对我不起作用。这是我的完整示例:

#include <GL/glew.h>
#include <GL/glfw.h>
#include <GL/glu.h>
#include <iostream>

typedef unsigned int uint;

int main()
{
    if (glfwInit() != 1)
    {
        return 1;
    }

    const uint width = 256;
    const uint height = 256;

    if (glfwOpenWindow(width, height, 8, 8, 8, 0, 24, 0, GLFW_WINDOW) != 1)
    {
        return 1;
    }

    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        std::cerr << glewGetErrorString(err) << std::endl;
        return 1;
    }

    GLuint r;
    glGenRenderbuffers(1, &r);
    glBindRenderbuffer(GL_RENDERBUFFER, r);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
    glBindRenderbuffer(GL_RENDERBUFFER, 0);

    GLuint r2;
    glGenRenderbuffers(1, &r2);
    glBindRenderbuffer(GL_RENDERBUFFER, r2);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, width, height);
    glBindRenderbuffer(GL_RENDERBUFFER, 0);

    GLuint f;
    glGenFramebuffers(1, &f);
    glBindFramebuffer(GL_FRAMEBUFFER, f);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, r);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, r2);
    std::cout << (glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) << std::endl;
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    std::cout << gluErrorString(glGetError()) << std::endl;

    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
    glBindFramebuffer(GL_READ_FRAMEBUFFER, f);
    glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST);

    std::cout << gluErrorString(glGetError()) << std::endl;

    return 0;
}

我得到的输出:

1
no error
invalid operation

24inglfwOpenWindow是深度位数。我究竟做错了什么?

4

2 回答 2

2

glfwOpenWindow要指定所需值的参数。但是,您的驱动程序完全有可能不支持您要求的确切格式(24 位颜色、24 位深度、无 alpha、无模板)。GLFW 将尝试在满足您的最低要求的同时找到最佳匹配。

在这种情况下,它可能会为您提供最标准的 RGBA 颜色格式(32 位)和 24/8 位深度/模板缓冲区,或者它可以创建 32 位深度缓冲区。您实际上需要调用glfwGetWindowParam以查询默认帧缓冲区的深度和模板位,然后构建您的渲染缓冲区以匹配它。

于 2015-08-28T21:39:24.967 回答
0

正如 ThomasD 在评论中所建议的那样GL_DEPTH24_STENCIL8有效。

于 2015-08-31T14:21:05.083 回答