Look for code which renders a scene to a texture. I'm sure you'll find plenty - even for the latest OpenGL's version.