为什么glBindFramebuffer(GL_FRAMEBUFFER,0)导致cocos2D-iphone中的空白屏幕?

JTh*_*ora 10 screen opengl-es framebuffer opengl-es-2.0

[iPad-3] - [iOS 5.0] - [Objective-C] - [XCode 4.3.3] - [Cocos2D] - [openGL | ES 2.0]

我正在学习如何使用openGL | ES 2.0并且偶然发现帧缓冲对象(FBO)

信息: 我正在使用Cocos2D,它有很多超凡的绘图处理能力.我想这可能与这个问题有关.如果cocos的'default'帧缓冲区与绘制到屏幕的实际默认帧缓冲区不同,则可能导致错误绘制

我的问题: 在我的"helloworld.m"类的init函数中,如果我放置"glBindFrameBuffer(GL_FRAMEBUFFER,0);" 在任何地方,我只是得到一个空白屏幕!

-(id) init
{
if( (self=[super init])) 
{

CGSize winSize = [CCDirector sharedDirector].winSize;

glBindFramebuffer(GL_FRAMEBUFFER, 0);


CCSprite * spriteBG = [[CCSprite alloc] initWithFile:@"cocos_retina.png"];
spriteBG.position = ccp(512,384);
//[self addChild:spriteBG z:1];

[self scheduleUpdate];
_mTouchDown = NO;


_mSprite = [CCSprite spriteWithTexture:_mMainTexture];
_mSprite.position = ccp(512,384);
[self addChild:_mSprite];

self.isTouchEnabled = YES;

} return self;}
Run Code Online (Sandbox Code Playgroud)

我错过了一些基本而明显的东西吗?

据我所知,函数"glBindFramebuffer(GL_FRAMEBUFFER,0);" 只需将Framebuffer设置为0即可应用绘制到屏幕的默认帧缓冲区.

JTh*_*ora 24

问题是iOS或Cocos2D(或两者)都可以拥有唯一的帧缓冲.该唯一帧缓冲区的句柄将不同于0,并且每次可以不同.

要解决这个问题,我必须抓住当前FBO的句柄,做自定义Framebuffer的东西,然后在完成之后重新应用FBO的句柄.

创建一个变量以引用原始的Frame Buffer Object

GLint oldFBO;
Run Code Online (Sandbox Code Playgroud)

将当前使用的FBO句柄(即'GLint')分配给变量'oldFBO'

glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldFBO);

//here is when you would create or manipulate custom framebuffers.//
Run Code Online (Sandbox Code Playgroud)

之后,将原始FBO设置为当前帧缓冲区

glBindFramebuffer(GL_FRAMEBUFFER, oldFBO);
Run Code Online (Sandbox Code Playgroud)