I'm using a framebuffer object with a color buffer attachment to do some per-pixel hit testing. I'd like to render it to the screen for debugging and testing but right now all I'm getting is a big white nothingness. I assume I have to send some render command similar to glSwapBuffers(), but as开发者_如何学运维 I'm only using one buffer I don't know what it would be swapping to. Is there an equivalent command for using just one buffer?
Here's my setup:
// Store the real framebuffer
glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, (GLint*) ®ularFbo);
// Generate an offscreen framebuffer/renderbuffer for rendering the hit detection polys
// Create framebuffer
glGenFramebuffersOES(1, &hitDetectionFbo);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, hitDetectionFbo);
// Create colorbuffer
glGenRenderbuffersOES(1, &colorBuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorBuffer);
// Create storage (RGBA) for color buffer
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGBA8_OES, SCREEN_WIDTH, SCREEN_HEIGHT);
// Attach color buffer to framebuffer
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBuffer);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
This doesn't flag any glErrors but I'm clearly missing something, as nothing is appearing on screen after I switch over to my new FBO. The program will render just fine if I continue to use the original framebuffer (through a glBindFramebufferOES(GL_FRAMEBUFFER_OES, regularFbo)
call).
Thanks for the help, -S
On the iPhone platform, the only FBO that can be used directly as the backbuffer is the one that has a color buffer that has been allocated using:
[myEaglContext renderbufferStorage:GL_RENDERBUFFER fromDrawable: eaglLayer];
If you allocate a color buffer using glRenderbufferStorageOES, then it's a normal off-screen FBO, and the best way to make it show up the screen is to bind it to a texture and render a quad.
精彩评论