OpenGL Render to Texture
Render to texture is a very handy functionality.
But you now have like 4-5 draw calls for one single object. Worse, you might have different textures and swamping textures is expensive.
What Render to Texture allows is to render those pieces into another texture that you might use later. So you need to draw all pieces once into a new texture, save it and use that from now on.
Of course this is a simple example, there are way cooler ways to use RTT’s.
OpenGL supports fast crossplatform offscreen rendering through the GL_EXT_framebuffer_object extension.
To render to a texture using the framebuffer object you must
Create a framebuffer object
Bind the framebuffer object
Attach a texture to the Frame Buffer Object
If you need depth testing, create and attach a depth renderbuffer
Init as a depth buffer
Attach for depth
Render the stuff you need like you would do normally.
Unbind the Frame Buffer Object
Use the texture you rendered to the regular way.