我尝试按照将深度渲染缓冲区复制到深度缓冲区进行操作,但它对我不起作用。这是我的完整示例:
#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
24
inglfwOpenWindow
是深度位数。我究竟做错了什么?