I would like to rende开发者_运维问答r to a texture in OpenGL but make changes to the texture incrementally.
Here's how I imagine the process:
- Clear Color & glViewport() to texture size
- Draw original texture (glOrtho or something), how can I copy the original with perfect quality?
- Draw incremental changes
- Clear again, set viewport to screen size
- Draw scene & flip
Is there a more optimal way to do this?
You have two choices. If your hardware doesn't support FBOs, you will have to do like you've written. To draw the original texture, just draw a screen-sized quad with [0,1] texture coordinates. Make sure to use GL_NEAREST
as filtering mode and GL_CLAMP_TO_EDGE
as wrapping mode, to get an exact copy of the image. Then draw your incremental changes on top of it. When done, you can get the texture from the frame buffer by means of glCopyTexSubImage2D
.
When your hardware supports FBOs, you can get much more efficient. In that case, attach the texture to an FBO and render into it. This way you render directly into the texture and there is no need for a copy. You also do not need to copy the original texture, just don't clear the framebuffer (texture), and render right on top of the previous data. Read some introductory material on framebuffer objects for more information.
精彩评论