尝试附加纹理时,GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT [英] GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT when trying to attach texture
问题描述
尝试创建渲染为纹理的帧缓冲区后,出现错误GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
.我不知道出了什么问题,我们将不胜感激.
I get an error GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
after I try to create a framebuffer that renders to a texture. I can't figure out what is wrong, any help is greatly appreciated.
已修复!工作代码:
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
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_RGBA, 768, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glGenRenderbuffers(1, &rboID);
glBindRenderbuffer(GL_RENDERBUFFER, rboID);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 768, 1024);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glGenFramebuffers(1, &backFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, backFramebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboID);
[self checkFramebufferStatus];
glBindFramebuffer(GL_FRAMEBUFFER, 0);
注意:如果您的版本不起作用,请确保在每次调用后检查错误,并且在第一次调用之前清除错误,否则您将在此之前对代码进行错误检查.
Note: If your version doesn't work, make sure you check for errors after each and every call AND that you clear the error before your first call, else you'll be error-checking the code before that.
推荐答案
纹理可能不完整.纹理的默认MIN_FILTER指定了mipmapping,但是您仅提供了纹理级别0,因此纹理本身是不完整的.
It is likely that the texture is incomplete. The default MIN_FILTER for a texture specifies mipmapping, but you've provided only for Texture Level 0, so the texture itself is incomplete.
添加对glTexParamter的调用,以将MIN_FILTER设置为非映射模式之一.
Add calls to glTexParamter to set the MIN_FILTER to one of the non-mipmapped modes.
这篇关于尝试附加纹理时,GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!