我正在尝试渲染到纹理并随后使用纹理,但由于某种原因它不起作用。
如 Apple文档中所述,
首先,我分配 fbo 以渲染到纹理..
glGenFramebuffers(1, &read_framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, read_framebuffer);
然后我创建纹理并将其附加到该 fbo ..
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8_OES, 64, 64, 0, GL_RGBA,
GL_UNSIGNED_BYTE, NULL);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
texture, 0);
然后创建用于绘图的fbo..
glGenFramebuffers(1, &draw_framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, draw_framebuffer);
glGenRenderbuffers(1, &_colorRenderBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, _colorRenderBuffer);
[_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:_eaglLayer];
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, _colorRenderBuffer);
稍后在渲染循环部分..
glBindFramebuffer(GL_FRAMEBUFFER, read_framebuffer);
(...off-screen drawing the scene here...)
glBindFramebuffer(GL_FRAMEBUFFER, draw_framebuffer);
绑定应该包含我的屏幕外渲染图像的纹理..
glBindTexture(GL_TEXTURE_2D, texture);
(..draw the scene with texture applied here...)
但是,由于某种原因,纹理总是黑色的。我在这里缺少什么吗?