Search code examples
iphoneiosopengl-estexturestexture2d

Rendering a texture in another class' RenderBuffer/FrameBuffer in OpenGL ES 2.0 for iOS 5


I have two UIViews, each with their own separate renderBuffers and frameBuffers. They belong to different ViewControllers. I already have them connected via NSNotificationCenter, so that is all set.

I just need to basically render the texture in ClassAView's frameBuffer into ClassBView's frameBuffer. This seems like it should be pretty easy... I tried passing in the texture I have bound in ClassAView:

glBindTexture(GL_TEXTURE_2D, myClassATexture);

then after say, tapping the screen, I try passing the texture over to ClassBView:


// in ClassA:
[classBView addTexture:myClassATexture];

// In ClassB's addTexture method:
myClassBTexture = newTexture
glClear, glBindTexture, etc...
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
[self presentFramebuffer];

But it's resulting in a black screen. I tried to NSLog myClassATexture but it's printing out "0."

Anyway, how would I go about effectively passing along the already rendered texture in ClassA to ClassB?

I'm targeting iOS 5.0 so if there's an easy way to do it that requires iOS 5 I'm all ears. :)

Thanks a bunch!


Solution

  • A texture ID of 0 indicates no texture, so you need to make sure you're properly copying the texture ID to use later.