I have been having trouble finding straightforward code to render a scene to a texture in OpenGL ES (specifically for the iPhone, if that matters). I am interested in knowing the following:
- How do you render a scene to a texture in OpenGL ES?
- What parameters must you use to create a texture that is capable of being a render target in OpenGL ES?
- Are there any implications with applying this rendered texture to other primitives?
This is how I’m doing it.
I define a texture variable (I use Apple’s
Texture2Dclass, but you can use an OpenGL texture id if you want), and a frame buffer:Then at some point, I create the texture, frame buffer and attach the renderbuffer. This you only need to do it once:
Every time I want to render to the texture, I do:
About your question 3, that’s it, you can use the texture as if it is any other texture.