我在嘗試渲染紋理,隨後使用紋理,但由於某種原因它不起作用。渲染爲紋理:始終爲黑色紋理
如蘋果documentation描述,
首先我分配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...)
但是,由於某種原因,質感始終是黑色的。有什麼我在這裏失蹤?
在調用'glFramebufferTexture2D'後立即調用'glCheckFramebufferStatus(GL_FRAMEBUFFER)'返回的值是什麼? – prideout 2013-03-14 19:07:40
它返回36054 – Random 2013-03-15 07:43:14