问题
I wanted to very quickly to make a simple drawing app for iOS, but I can't quite get the drawing to work - well, to save the content on each layer and restore the layers. It appears like all layers save the same pixels..
The idea was to have three layers and use OpenGL ES to draw on each layer. With no experience in the matter, I just tiled three UIViews and added a OpenGL drawing canvas to each UIView (a modified version of the PaintingView from the tutorial). When the user swapped drawing layer, I simply disabled user interaction on the other layers.
With this approach I experience a lot of oddities that I assume stems from my approach. So now, I think that I should somehow make three full screen buffers in the same PaintingView and just have OpenGL switch between them.
Am I on to something? Have anyone an approach that works?
Anything on-topic might help. Thanks.
回答1:
You can make two different framebuffers: one for drawing to screen and second for drawing to texture. Then, you can make 3 different textures, they will be your layers. Draw to them. Finally, you can draw the textures you have to the first framebuffer and present in on screen.
Your draw cycle will be smth like this:
- bind RenderToTextureFramebuffer
- attach texture1 to RenderToTextureFramebuffer
- draw what you want in layer 1
- attach texture2 to RenderToTextureFramebuffer
- draw what you want in layer 2
- attach texture3 to RenderToTextureFramebuffer
- draw what you want in layer 3
- bind RenderToScreenFramebuffer
- bind texture1
- draw texture1 (your layer1)
- bind texture2
- draw texture2 (your layer2)
- bind texture3
- draw texture3 (your layer3)
- present final picture on screen
回答2:
to have all functionality of painters - undo/redo and so on IMHO you need to have just several arrays of graphic objects and iterate through them on every render pass.
来源:https://stackoverflow.com/questions/11901721/how-to-achieve-multi-layered-drawing-with-opengl-es-on-ios