我想用 OpenGL 创建一个屏幕外渲染器。
我创建了 aFBO
和 aRBO
来调用glReadPixels()
,但总是出错。
这是我的代码:
// Init
GLuint fbo;
GLuint rbo;
glGenFramebuffers(1, &fbo);
glGenRenderbuffers(1, &rbo);
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, width, height);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
glClearColor(0.0f, 1.0f, 1.0f, 1.0f);
// Render loop
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
...
std::vector<unsigned char> output(width * height * 4);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, &output[0]);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
// Deinit
glDeleteRenderbuffers(1, &rbp);
glDeleteFramebuffers(1, &fbo);
输出不包含任何内容,并且glGetError()
函数总是1282 (GL_INVALID_OPERATION)
在调用glReadPixels()
.
这段代码有什么问题?