我目前正在iPhone上用OpenGL ES 2.0绘制对象(图像、矩形)。
有两种模式:
( A)没有FBO:
( B)与FBO
现场抽奖顺序是:
以下是结果(左不带FBO,右侧为FBO):
1)没有透明度的图像:两者是相同的


2)透明度设置为0.5,红色背景:两者不同


3)透明度设置为0.5,黑色背景:右与1)无透明度


下面是我如何创建FBO的方法:
GLint maxRenderBufferSize;
glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxRenderBufferSize);
GLuint textureWidth = (GLuint)self.size.width;
GLuint textureHeight = (GLuint)self.size.height;
if(maxRenderBufferSize <= (GLint)textureWidth || maxRenderBufferSize <= (GLint)textureHeight)
@throw [NSException exceptionWithName:TAG
reason:@"FBO cannot allocate that much space"
userInfo:nil];
glGenFramebuffers(1, &fbo);
glGenRenderbuffers(1, &fboBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glGenTextures(1, &fboTexture);
glBindTexture(GL_TEXTURE_2D, fboTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboTexture, 0);
glBindRenderbuffer(GL_RENDERBUFFER, fboBuffer);
GLuint status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE)
@throw [NSException exceptionWithName:TAG
reason:@"Failed to initialize fbo"
userInfo:nil];这是我的碎片着色器:
gl_FragColor = (v_Color * texture2D(u_Texture, v_TexCoordinate));发布于 2017-08-22 09:52:50
发现问题时,这一行是我的呈现-FBO-to-window函数中的问题:
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);我只是删除它,因为我不需要阿尔法混合在这一步。
https://stackoverflow.com/questions/45813879
复制相似问题