iOS的OpenGL ES – 渲染屏幕上的FBO应用程序退出稍后重绘

我想把我的屏幕渲染成纹理,这样当我再次回到应用程序时,我可以将纹理“粘贴”到屏幕上。 目前在我的应用程序中,我正在绘制一个kEAGLDrawablePropertyRetainedBacking设置为TRUE的波形。 它的工作原理,但我离开我的应用程序,并再次回来后屏幕被清除。 kEAGLDrawablePropertyRetainedBacking TRUE是否正常? 当我回到我的应用程序时,我再也买不起fps了。

我已经偶然发现了这个问题: 如何在OpenGL ES中保存和重画屏幕内容,并试图将答案应用于我的需求,但是我仍然遇到问题。

参考另一个问题的答案,我试图做到这一点。

@property (nonatomic) GLuint framebuffer; @property (nonatomic) GLuint texture; 

在glkviewcontroller加载的代码。

 - (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive) name:UIApplicationWillResignActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillTerminate) name:UIApplicationWillTerminateNotification object:nil]; glGenFramebuffers(1, &_framebuffer); glBindFramebuffer(GL_FRAMEBUFFER_OES, _framebuffer); glGenTextures(1, &_texture); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, _texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 768, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); ..... 

当这个viewController被通知应用程序正在辞职时,我使用这个函数:

  -(void)appWillResignActive { glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, _texture, 0); if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) NSLog(@"Error!"); } 

检查上面的状态后,我仍然收到错误。 这里可能是什么问题? 我对OpenGL ES很新,请原谅,如果这是一个新手问题。 谢谢。

没关系我正在尝试上下文初始化之前的纹理和framebuffer绑定。

  // Create an OpenGL ES 2.0 context and provide it to the // view view.context = [[AGLKContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; view.delegate = self; // Make the new context current [AGLKContext setCurrentContext:view.context]; 

在此之后放置代码允许检查通过。