Render-to-texture in OpenGL involves creating a framebuffer object (FBO) and attaching it to a texture. Have a look at the documentation for framebuffer objects for a basic overview.
The general workflow is like this:
- Create a framebuffer object with glGenFramebuffers
- Activate the framebuffer with glBindFramebuffer
- Attach the framebuffer to the texture you want to render to with glFramebufferTexture
- Call glCheckFramebufferStatus to ensure that it worked.
- Set the viewport to match the dimensions of the texture you're rendering to. (This generally involves calling glViewport and glOrtho, which I'm sure you're already familiar with so I won't link them here.)
- Do your rendering.
- When you're done, deactivate the FBO (call glBindFramebuffer again and pass 0 as the FBO ID value) and reset your viewport.
- Whatever you've rendered should now be there in the texture.