如何在iOS上使用OpenGL ES实现多层绘图? [英] How to achieve multi-layered drawing with OpenGL ES on iOS?
问题描述
我想很快为iOS制作一个简单的绘图应用程序,但我无法完成绘图工作 - 好吧,保存每个图层上的内容并恢复图层。看起来所有图层都保存相同的像素。
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..
这个想法是有三层,并使用OpenGL ES在每一层上绘制。由于没有这方面的经验,我只是平铺了三个UIViews,并为每个UIView(教程中的PaintingView的修改版本)添加了一个OpenGL绘图画布。当用户交换绘图层时,我只是禁用了其他图层上的用户交互。
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.
通过这种方法,我经历了很多奇怪的事情,我认为这些怪异源于我的方法。所以现在,我认为我应该以相同的方式在同一个PaintingView中制作三个全屏缓冲区,并且只需在它们之间进行OpenGL切换。
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.
推荐答案
您可以制作两个不同的帧缓冲区:一个用于绘制到屏幕,另一个用于绘制到纹理。
然后,您可以制作3种不同的纹理,它们将是您的图层。吸引他们。
最后,你可以将你拥有的纹理绘制到第一个帧缓冲区并显示在屏幕上。
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
- 将texture1附加到RenderToTextureFramebuffer
- 画出你的内容希望在第1层
- 将texture2附加到RenderToTextureFramebuffer
- 在第2层中绘制所需内容
- 附加texture3 to RenderToTextureFramebuffer
- 在第3层中绘制你想要的东西
- bind RenderToScreenFramebuffer
- bind texture1
- 绘制texture1(你的layer1)
- 绑定texture2
- 绘制texture2(你的layer2)
- 绑定texture3
- 绘制texture3(你的layer3)
- 在屏幕上显示最终图片
- 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
这篇关于如何在iOS上使用OpenGL ES实现多层绘图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!