我想用OpenGL创建一个屏幕外渲染器。
我已经创建了mGPUImageView.setImage(bitmapSharpness);
和FBO
来调用RBO
,但我总是收到错误。
这是我的代码:
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)
。
此代码的问题是什么?